01: /* $Id: AuthenticatorHandler.java,v 1.1.1.1 2002/10/02 18:42:51 wastl Exp $ */
02: package net.wastl.webmail.server;
03:
04: import net.wastl.webmail.config.*;
05: import net.wastl.webmail.exceptions.WebMailException;
06: import java.io.*;
07: import java.util.*;
08:
09: /**
10: * AuthenticatorHandler.java
11: *
12: * Created: Wed Sep 1 15:04:04 1999
13: *
14: * Copyright (C) 1999-2000 Sebastian Schaffert
15: *
16: * This program is free software; you can redistribute it and/or
17: * modify it under the terms of the GNU General Public License
18: * as published by the Free Software Foundation; either version 2
19: * of the License, or (at your option) any later version.
20: *
21: * This program is distributed in the hope that it will be useful,
22: * but WITHOUT ANY WARRANTY; without even the implied warranty of
23: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24: * GNU General Public License for more details.
25: *
26: * You should have received a copy of the GNU General Public License
27: * along with this program; if not, write to the Free Software
28: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29: */
30: /**
31: *
32: * @author Sebastian Schaffert
33: * @version
34: */
35:
36: public class AuthenticatorHandler {
37:
38: WebMailServer parent;
39:
40: Hashtable authenticators;
41:
42: String authenticator_list;
43:
44: public AuthenticatorHandler(WebMailServer parent)
45: throws WebMailException {
46: this .parent = parent;
47:
48: authenticator_list = parent
49: .getProperty("webmail.authenticators");
50: if (authenticator_list == null) {
51: throw new WebMailException(
52: "No Authenticators defined (parameter: webmail.authenticators)");
53: }
54:
55: parent.getConfigScheme().configRegisterChoiceKey("AUTH",
56: "Authentication method to use.");
57: //parent.getConfigScheme().configRegisterStringKey("AUTHHOST","localhost","Host used for remote authentication (e.g. for IMAP,POP3)");
58: registerAuthenticators();
59: parent.getConfigScheme().setDefaultValue("AUTH", "IMAP");
60: }
61:
62: /**
63: * Initialize and register WebMail Authenticators.
64: */
65: public void registerAuthenticators() {
66: System.err
67: .println("- Initializing WebMail Authenticator Plugins ...");
68:
69: StringTokenizer tok = new StringTokenizer(authenticator_list,
70: ":;, ");
71:
72: authenticators = new Hashtable();
73: while (tok.hasMoreTokens()) {
74: String name = (String) tok.nextToken();
75: try {
76: Class c = Class.forName(name);
77: Authenticator a = (Authenticator) c.newInstance();
78: a.register(parent.getConfigScheme());
79: authenticators.put(a.getKey(), a);
80: System.err
81: .println(" * registered authenticator plugin \""
82: + c.getName() + "\"");
83: } catch (Exception ex) {
84: System.err.println(" * Error: could not register \""
85: + name + "\" (" + ex.getMessage() + ")!");
86: //ex.printStackTrace();
87: }
88: }
89: System.err.println(" done!");
90: }
91:
92: public Authenticator getAuthenticator(String key) {
93: return (Authenticator) authenticators.get(key);
94: }
95:
96: } // AuthenticatorHandler
|