01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
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
26: .getName());
27: private static boolean init = false;
28:
29: private static String remoteHost = "127.0.0.1";
30: private static int remotePort = 8080;
31:
32: public boolean askAuthorisation(ClientHandler clientHandler)
33: throws IOException, AppException {
34: logger.fine("inside");
35: if (init == false) {
36: init(clientHandler);
37: }
38:
39: Data data = (Data) clientHandler.getClientData();
40: data.setRemoteHost(remoteHost);
41: data.setRemotePort(remotePort);
42: try {
43: data.init(new Socket(data.getRemoteHost(), data
44: .getRemotePort()), clientHandler);
45: return true;
46: } catch (Exception e) {
47: logger.severe("Error : " + e);
48: return false;
49: }
50: }
51:
52: private static void init(ClientHandler clientHandler) {
53: HashMap appConfig = clientHandler.getServer().getConfig()
54: .getApplicationConfiguration();
55: if (appConfig != null) {
56: String temp = null;
57: try {
58: temp = (String) appConfig.get("REMOTE_HOST");
59: if (temp != null)
60: remoteHost = temp;
61:
62: temp = (String) appConfig.get("REMOTE_PORT");
63: if (temp != null)
64: remotePort = Integer.parseInt(temp);
65:
66: init = true;
67: } catch (Exception e) {
68: logger.severe("Error loading app. properties : " + e);
69: }
70: }
71: }
72: }
|