AuthenticatorHandler.java
上传用户:huihesys
上传日期:2007-01-04
资源大小:3877k
文件大小:3k
- /* $Id: AuthenticatorHandler.java,v 1.2 2000/04/06 08:02:02 wastl Exp $ */
- package net.wastl.webmail.server;
- import net.wastl.webmail.config.*;
- import java.io.*;
- import java.util.*;
- /**
- * AuthenticatorHandler.java
- *
- * Created: Wed Sep 1 15:04:04 1999
- *
- * Copyright (C) 1999-2000 Sebastian Schaffert
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /**
- *
- * @author Sebastian Schaffert
- * @version
- */
- public class AuthenticatorHandler {
-
- WebMailServer parent;
- String auth_path;
- Hashtable authenticators;
- public AuthenticatorHandler(WebMailServer parent) {
- this.parent=parent;
- this.auth_path=parent.getProperty("webmail.auth.path");
- parent.getConfigScheme().configRegisterChoiceKey("AUTH","Authentication method to use.");
- //parent.getConfigScheme().configRegisterStringKey("AUTHHOST","localhost","Host used for remote authentication (e.g. for IMAP,POP3)");
- registerAuthenticators();
- }
- /**
- * Initialize and register WebMail Authenticators.
- */
- public void registerAuthenticators() {
- System.err.println("- Initializing WebMail Authenticator Plugins ...");
- File f=new File(auth_path);
- if(!f.canRead() || !f.isDirectory()) {
- System.err.println("Can't read directory "+auth_path);
- }
- String[] classlist=f.list(new FFilter());
- authenticators=new Hashtable();
- for(int i=0;classlist != null && i<classlist.length;i++) {
- String name=classlist[i].substring(0,classlist[i].length()-6);
- try {
- Class c=Class.forName(name);
- Authenticator a=(Authenticator) c.newInstance();
- a.register(parent.getConfigScheme());
- authenticators.put(a.getKey(),a);
- System.err.println(" * registered authenticator plugin ""+c.getName()+""");
- } catch(Exception ex) {
- System.err.println(" * Error: could not register ""+name+"" ("+ex.getMessage()+")!");
- //ex.printStackTrace();
- }
- }
- System.err.println(" done!");
- }
- public Authenticator getAuthenticator(String key) {
- return (Authenticator)authenticators.get(key);
- }
-
- /**
- * A filter to find WebMail Plugins.
- */
- class FFilter implements FilenameFilter {
- FFilter() {
- }
-
- public boolean accept(File f, String s) {
- if(s.endsWith(".class")) {
- return true;
- } else {
- return false;
- }
- }
- }
-
- } // AuthenticatorHandler