KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > pipeserver > Authenticator


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

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 JavaDoc 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 JavaDoc 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 JavaDoc temp = null;
55             try {
56                 temp = (String JavaDoc) appConfig.get("REMOTE_HOST");
57                 if(temp!=null) remoteHost = temp;
58
59                 temp = (String JavaDoc) appConfig.get("REMOTE_PORT");
60                 if(temp!=null) remotePort = Integer.parseInt(temp);
61
62                 init = true;
63             } catch(Exception JavaDoc e) {
64                 logger.severe("Error loading app. properties : "+e);
65             }
66         }
67     }
68 }
69
Popular Tags