📄 accessserver.java
字号:
/******************************************************************************* * Copyright (C) 2002, 2003 * ingenieurbuero fuer innovative informationstechnik (iiit) * Dipl.-Ing. Joerg Beckmann, Dortmund, Germany * * 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. * * version $Id: AccessServer.java,v 1.12 2003/04/14 20:05:01 joerg Exp $ ******************************************************************************/package de.iiit.access.server;import de.iiit.access.server.api.*;import de.iiit.ldap.*;import de.iiit.xmlconfig.*;import de.iiit.util.*;import java.util.*;import org.apache.log4j.*;/** This is the AccessServer's main class. * @version $Revision: 1.12 $ $Date: 2003/04/14 20:05:01 $ */public class AccessServer{ /** CVS Version Tag */ private static final String vcid = "$Id: AccessServer.java,v 1.12 2003/04/14 20:05:01 joerg Exp $"; /** Name of the configuration file */ private static final String CONFIG_FILE = "AccessServer.xml"; /** Config variable for the logging level */ private static final String CONFIG_VAR_LOGLEVEL = "LogLevel"; private static final String CONFIG_IGNORE_CASE = "IgnoreCase"; private static final String CONFIG_VERIFY_USER = "VerifyUser"; /** Config variable for the class name of the plug-in to load */ private static final String CONFIG_VAR_PLUGINCLASS = "PluginClass"; private static final String CONFIG_TCPSERVER = "TcpServer"; private static final String CONFIG_LOGGER = "Logger"; private static final String CONFIG_LDAPPLUGIN = "LdapPlugin"; private static final String CONFIG_CACHEPLUGIN = "CachePlugin"; private static final String CONFIG_THREADPLUGIN = "ThreadPlugin"; private static final String CONFIG_RESOLVERPLUGIN = "ResolverPlugin"; private static final String CONFIG_PLUGINCONFIG = "PluginConfig"; private static CachePluginIf cachePlugin = null; private static ResolverPluginIf resolverPlugin = null; private static Vector threadPlugins = new Vector(); private static boolean ignoreCase = false; private static boolean verifyUser = true; private static Configuration config = null; private static Logger logger = Logger.getLogger("AccessServer"); /** Creates a new instance of AccessServer */ private AccessServer() { } private static Configuration getConfiguration() throws Exception { Configuration result = null; String filename = FileSearch.search(CONFIG_FILE); if (filename == null) { System.out.println("File <" + CONFIG_FILE + "> not found in <" + FileSearch.getSearchPathAsString() + ">"); } else { result = Configuration.load(filename); } return result; } private static AccessServerPluginIf loadPlugin(Configuration config) throws ClassNotFoundException, InstantiationException, IllegalAccessException { AccessServerPluginIf plugin = null; String pluginClass = config.getAttribute(CONFIG_VAR_PLUGINCLASS); Class c = Class.forName(pluginClass); plugin = (AccessServerPluginIf) c.newInstance(); Configuration pluginCfg = config.getSubConfiguration(CONFIG_PLUGINCONFIG); plugin.initialize(pluginCfg); return plugin; } /** Get cache plug-in. * @return Returns a previous loaded cache plug-in or null if none is loaded. * */ public static ResolverPluginIf getResolverPlugin() { return resolverPlugin; } /** Get cache plug-in. * @return Returns a previous loaded cache plug-in or null if none is loaded. * */ public static CachePluginIf getCachePlugin() { return cachePlugin; } /** Retrieve a single sub-configuration with a given name. If there is more than one * Block with this name only the first of them is returned. * @param name The name of the sub-configuration * @return The sub-configuration or null if there is no one with the given name. */ public static Configuration getSubConfiguration(String name) { return config.getSubConfiguration(name); } /** Get all sub-configurations of the current configuration with a given name * @param name The name of the sub-configuration to retrieve * @return A <I>Vector</I> with the retrieved <I>Configuration</I> Object or <B>null</B> if there is no * sub-configuration with the given <I>name</I>. */ public static Vector getSubConfigurations(String name) { return config.getSubConfigurations(name); } /** Shuts the whole <I>iiitAccessServer</I> down. */ public static void shutDown() { logger.info("Shutting down all threads."); if (cachePlugin != null) cachePlugin.shutdown(); if (resolverPlugin != null) resolverPlugin.shutdown(); Enumeration enum = threadPlugins.elements(); while (enum.hasMoreElements()) ((ThreadPluginIf) enum.nextElement()).shutdown(); // Interrupting all threads Thread thread = Thread.currentThread(); ThreadGroup tg = thread.getThreadGroup(); while(tg.getParent() != null) tg = tg.getParent(); tg.interrupt(); logger.info("Done."); } /** Sets whether the <I>iiitAccessServer</I> should ignore case or not. * @param flag true forces ignoration of upper- and lower-case. */ public static void setIgnoreCase(boolean flag) { ignoreCase = flag; } /** Retrieves whether upper- and lower-case shall be ignored * @return true if upper- and lower-case shall be ignored, false if not. */ public static boolean getIgnoreCase() { return ignoreCase; } /** Sets the "VerifyUser"-flag. If the flag is set to <b>true</b>, user names will * be verified against the user databases. If it is set to false, user names will * not be verified at all. * @param flag the flag as described above. */ public static void setVerifyUser(boolean flag) { verifyUser = flag; } /** Retrieves the "VerifyUser"-flag. * @return true if user names will be verified, false if not. * @see AccessServer#setVerifyUser */ public static boolean getVerifyUser() { return verifyUser; } /** This is the main method of AccessServer. It reads the configuration, loads all * configured plug-ins, initializes all sub-systems and starts the background * threads. * @param args the command line arguments */ public static void main(String[] args) { try { config = getConfiguration(); if (config == null) { System.out.println("No configuration read"); } else { ignoreCase = config.getBooleanAttribute(CONFIG_IGNORE_CASE, false); verifyUser = config.getBooleanAttribute(CONFIG_VERIFY_USER, true); Configuration subConfig = config.getSubConfiguration(CONFIG_LOGGER); if (subConfig != null) LogUtil.init(subConfig, Level.DEBUG); else { String level = config.getAttribute(CONFIG_VAR_LOGLEVEL); LogUtil.init(level, Level.DEBUG); } if (config != null && logger.isDebugEnabled()) { logger.debug("Configuration:"); config.printConfig(); } subConfig = config.getSubConfiguration(CONFIG_RESOLVERPLUGIN); if (subConfig != null) { logger.info("Loading resolver plugin"); resolverPlugin = (ResolverPluginIf) loadPlugin(subConfig); } subConfig = config.getSubConfiguration(CONFIG_CACHEPLUGIN); if (subConfig != null) { logger.info("Loading cache plugin"); cachePlugin = (CachePluginIf) loadPlugin(subConfig); } Vector cfgVector = config.getSubConfigurations(CONFIG_THREADPLUGIN); if (cfgVector != null) { logger.info("Loading thread plugins"); int iMax = cfgVector.size(); for (int i = 0; i < iMax; i++) { ThreadPluginIf thread = (ThreadPluginIf) loadPlugin((Configuration) cfgVector.get(i)); threadPlugins.add(thread); } } if (cachePlugin != null) cachePlugin.start(); Enumeration enum = threadPlugins.elements(); while (enum.hasMoreElements()) ((ThreadPluginIf) enum.nextElement()).start(); } } catch(Exception e) { e.printStackTrace(System.err); } }}/** * $Log: AccessServer.java,v $ * Revision 1.12 2003/04/14 20:05:01 joerg * Sending interrupts to all thread to force shut down. * * Revision 1.11 2003/04/13 20:16:41 joerg * Package structure modified * * Revision 1.10 2003/04/07 20:14:53 joerg * Improved JavaDoc. * * Revision 1.9 2003/04/07 20:08:49 joerg * Improved JavaDoc. * * Revision 1.8 2003/04/07 16:42:34 joerg * Deprecated class ConfigReader no longer used. * * Revision 1.7 2003/03/30 20:46:22 joerg * Ongoing development * * Revision 1.6 2003/01/17 19:55:48 joerg * Neue Globale Config-Variable VerifyUser * * Revision 1.5 2003/01/04 17:15:42 joerg * Zus鋞zliche Config-Option IgnoreCase * * Revision 1.4 2003/01/01 21:04:17 joerg * Copyright-Statement aktualisiert * * Revision 1.3 2002/12/23 11:27:34 joerg * Auch resolver bekommen jetzt ein shutdown() geschickt. * * Revision 1.2 2002/12/22 21:02:29 joerg * Log-Ausgaben beim shutdown() * * Revision 1.1 2002/12/19 15:24:23 joerg * Reparatur des CVS-Repositories * * Revision 1.21 2002/12/09 21:14:15 joerg * AccessServerThreadPluginIf umbenannt in ThreadPluginIf * * Revision 1.20 2002/12/09 19:29:17 joerg * Versionsdaten in allen JavaDoc-Klassenbeschreibungen ergaenzt * * Revision 1.19 2002/12/09 16:32:26 joerg * JavaDoc Kommentare ergaenzt * * Revision 1.18 2002/12/08 16:36:24 joerg * Aufraeumungsarbeiten nach dem grossen Umbau * * Revision 1.17 2002/12/08 16:20:51 joerg * Aufraeumungsarbeiten nach dem grossen Umbau * * Revision 1.16 2002/12/08 14:35:01 joerg * Plugin-Interface neu strukturiert * * Revision 1.15 2002/12/08 13:48:39 joerg * LdapPlugin entfernt * Neue Zugriffsmethoden fuer Module auf die zentrale Configuration * * Revision 1.14 2002/12/07 20:32:34 joerg * Neue init()-Methode der LogUtils eingebaut * * Revision 1.13 2002/11/26 10:56:13 joerg * Package exprparser durch parser erstzt. * * Revision 1.12 2002/11/19 20:27:10 joerg * Das Cache-Plugin muss auch gestartet werden :-) * * Revision 1.11 2002/11/19 20:24:42 joerg * Fuer den Cache kann jetzt auch ein Plugin geladen werden. * * Revision 1.10 2002/11/19 11:02:53 joerg * CacheManager zum Plugin umgebaut * * Revision 1.9 2002/11/18 21:22:57 joerg * LDAP-Anbindung auf LdapPlugin umgestellt. * * Revision 1.8 2002/11/18 15:22:43 joerg * Klassen des CacheManagers in eigenes Package verschoben * * Revision 1.7 2002/11/17 22:04:57 joerg * Aufruf fuer CacheManager * * Revision 1.6 2002/11/06 08:24:06 joerg * Initialisierung des LDAP-Clients eingebaut. * * Revision 1.5 2002/11/03 20:34:30 joerg * Klasse TcpListener umbenannt in TcpServer * * Revision 1.4 2002/11/03 19:42:16 joerg * Klasse LogInit in LogUtil umbenannt * * Revision 1.3 2002/11/03 19:39:19 joerg * Methode printConfig() von Klasse ConfigReader in Klasse Configuration verschoben * * Revision 1.2 2002/11/03 15:10:19 joerg * Klasse 'ConfigurationElement' umbenannt in 'Configuration' * * Revision 1.1 2002/11/03 14:45:03 joerg * Klassen neu angelegt * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -