1 14 15 package pipeserver; 16 17 import org.quickserver.net.server.*; 18 import org.quickserver.net.AppException; 19 import java.io.*; 20 import java.util.*; 21 import java.util.logging.*; 22 import java.net.*; 23 24 public class Authenticator extends QuickAuthenticator { 25 private static Logger logger = Logger.getLogger(Authenticator.class.getName()); 26 private static boolean init = false; 27 28 private static String remoteHost = "127.0.0.1"; 29 private static int remotePort = 8080; 30 31 public boolean askAuthorisation(ClientHandler clientHandler) 32 throws IOException, AppException { 33 logger.fine("inside"); 34 if(init==false) { 35 init(clientHandler); 36 } 37 38 Data data = (Data) clientHandler.getClientData(); 39 data.setRemoteHost(remoteHost); 40 data.setRemotePort(remotePort); 41 try { 42 data.init(new Socket(data.getRemoteHost(), 43 data.getRemotePort()), clientHandler); 44 return true; 45 } catch(Exception e) { 46 logger.severe("Error : "+e); 47 return false; 48 } 49 } 50 51 private static void init(ClientHandler clientHandler) { 52 HashMap appConfig = clientHandler.getServer().getConfig().getApplicationConfiguration(); 53 if(appConfig!=null) { 54 String temp = null; 55 try { 56 temp = (String ) appConfig.get("REMOTE_HOST"); 57 if(temp!=null) remoteHost = temp; 58 59 temp = (String ) appConfig.get("REMOTE_PORT"); 60 if(temp!=null) remotePort = Integer.parseInt(temp); 61 62 init = true; 63 } catch(Exception e) { 64 logger.severe("Error loading app. properties : "+e); 65 } 66 } 67 } 68 } 69 | Popular Tags |