1 14 15 package org.quickserver.net.server; 16 17 import java.io.*; 18 import java.net.SocketTimeoutException; 19 import org.quickserver.net.AppException; 20 21 65 public class ServerAuthenticator implements Authenticator { 66 67 protected String error; 68 69 protected BufferedReader in; 70 71 protected OutputStream out; 72 73 protected PrintWriter pout; 74 protected ClientData data; 75 protected ClientHandler handler; 76 77 78 protected String username; 79 80 protected String password; 81 82 private boolean freeOnUse = true; 84 85 89 private final void setInputOutput(BufferedReader in, 90 OutputStream out) { 91 this.in = in; 92 this.out = out; 93 pout = new PrintWriter(out,true); 94 } 95 96 109 public boolean askAuthorisation() 110 throws IOException, AppException { 111 return true; 112 } 113 114 public boolean askAuthorisation(ClientHandler clientHandler) 115 throws IOException, AppException { 116 if(getClientHandler()==null) 117 setClientHandler(clientHandler); 118 return askAuthorisation(); 119 } 120 121 127 public String getError() { 128 String temp = error; 129 error = null; 130 return temp; 131 } 132 136 public void setError(String error) { 137 this.error = error; 138 } 139 140 148 public void cleanup() { 149 pout = null; 150 in = null; 151 out = null; 152 data = null; 153 handler = null; 154 } 155 156 162 private final void setClientData(ClientData data) { 163 this.data = data; 164 } 165 166 171 public ClientData getClientData() { 172 return getClientHandler().getClientData(); 173 } 174 175 180 public final void setClientHandler(ClientHandler handler) { 181 this.handler = handler; 182 setClientData(handler.getClientData()); 183 setInputOutput(handler.getBufferedReader(), 184 handler.getOutputStream()); 185 } 186 187 194 public ClientHandler getClientHandler() { 195 return handler; 196 } 197 198 206 public void setFreeOnUse(boolean flag) { 207 this.freeOnUse = flag; 208 } 209 215 public boolean getFreeOnUse() { 216 return freeOnUse; 217 } 218 } 219 | Popular Tags |