📄 coreservlet.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.core;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.security.auth.login.Configuration;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.event.EventListenerList;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.PlugInConfig;
import org.apache.struts.util.MessageResourcesFactory;
import org.apache.struts.util.RequestUtils;
import com.sslexplorer.activedirectory.ActiveDirectoryUserDatabase;
import com.sslexplorer.boot.ContextHolder;
import com.sslexplorer.boot.ContextListener;
import com.sslexplorer.boot.PropertyDefinition;
import com.sslexplorer.boot.Util;
import com.sslexplorer.boot.XMLElement;
import com.sslexplorer.extensions.store.ExtensionStore;
import com.sslexplorer.jdbc.JDBCPropertyDatabase;
import com.sslexplorer.jdbc.JDBCUserDatabase;
import com.sslexplorer.jdbc.hsqldb.EmbeddedHSQLDBServer;
import com.sslexplorer.keystore.wizards.KeyStoreImportTypeManager;
import com.sslexplorer.keystore.wizards.types.ReplyFromCAImportType;
import com.sslexplorer.keystore.wizards.types.RootServerCertificateImportType;
import com.sslexplorer.keystore.wizards.types.ServerAuthenticationKeyImportType;
import com.sslexplorer.keystore.wizards.types.TrustedServerCertificateImportType;
import com.sslexplorer.keystore.wizards.types._3SPPurchaseImportType;
import com.sslexplorer.navigation.NavigationBar;
import com.sslexplorer.navigation.NavigationManager;
import com.sslexplorer.notification.Notifier;
import com.sslexplorer.notification.smtp.SMTPMessageSink;
import com.sslexplorer.notification.vpnclient.VPNClientMessageSink;
import com.sslexplorer.plugin.Plugin;
import com.sslexplorer.plugin.PluginDefinition;
import com.sslexplorer.plugin.PluginManager;
import com.sslexplorer.policyframework.PolicyDatabase;
import com.sslexplorer.properties.DefaultPropertyDefinitionCategory;
import com.sslexplorer.properties.PropertyDatabase;
import com.sslexplorer.properties.PropertyDefinitionCategory;
import com.sslexplorer.requesthandler.connect.ConnectRequestHandler;
import com.sslexplorer.requesthandler.test.TestRequestHandler;
import com.sslexplorer.reverseproxy.ReverseProxyMethodHandler;
import com.sslexplorer.security.AuthenticationModuleManager;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.EmbeddedClientAuthenticationModule;
import com.sslexplorer.security.HTTPAuthenticationModule;
import com.sslexplorer.security.LogonController;
import com.sslexplorer.security.PasswordAuthenticationModule;
import com.sslexplorer.security.PersonalQuestionsAuthenticationModule;
import com.sslexplorer.security.SystemDatabase;
import com.sslexplorer.security.UserAttributeDefinition;
import com.sslexplorer.security.UserDatabase;
import com.sslexplorer.security.WebDAVAuthenticationModule;
import com.sslexplorer.tasks.timer.StoppableTimer;
import com.sslexplorer.unixauth.UNIXUserDatabase;
import com.sslexplorer.vfs.clipboard.Clipboard;
/**
* Main controlling servlet. This extends struts own
* {@link org.apache.struts.action.ActionServlet}. Pretty much all SSL-Explorer
* actions will come through here.
* <p>
* Many features in SSL-Explorer require access to this servlet as it manages
* pages scripts, the logon controller, the policy database, the plugin manager,
* the system database and the events system.
* <p>
* Only a single instance of this servlet will ever exist, a reference to which
* is available through the static {@link #getServlet()} method.
*
* @author Brett Smith <brett@3sp.com>
*/
public class CoreServlet extends ActionServlet implements ContextListener {
/**
*
*/
private static final long serialVersionUID = 2175322073390766579L;
final static Log log = LogFactory.getLog(CoreServlet.class);
private static PluginManager pluginManager;
private static CoreServlet instance;
// Private instance variables
private ModuleConfig moduleConfig;
private HashMap resourceBases;
private Class logonControllerClass;
private Class systemDatabaseClass;
private Class policyDatabaseClass;
private LogonController logonController;
private UserDatabase userDatabase;
private PropertyDatabase propertyDatabase;
private SystemDatabase systemDatabase;
private PolicyDatabase policyDatabase;
private CoreMessageResources applicationStoreResources;
private EventListenerList coreListeners;
private boolean logonControllerLocked;
private StringBuffer tileConfigFiles = new StringBuffer();
private MessageResourcesFactory messageResourcesFactory;
private ConnectRequestHandler connectProxyMethodHandler;
private List pageScripts;
private Notifier notifier;
private UpdateChecker updateChecker;
private EmbeddedHSQLDBServer dbServer;
private boolean shuttingDown;
/**
* Constructor
*/
public CoreServlet() {
super();
instance = this;
updateChecker = new UpdateChecker();
pageScripts = new ArrayList();
resourceBases = new HashMap();
coreListeners = new EventListenerList();
NavigationManager.addMenuTree(new CoreMenuTree());
NavigationManager.addMenuTree(new PageTaskMenuTree());
NavigationManager.addMenuTree(new NavigationBar());
Configuration.setConfiguration(new CoreJAASConfiguration());
addTileConfigurationFile("/WEB-INF/tiles-defs.xml");
// Make sure that Http redirects are followed in places where we use URL
// to connect to our website
HttpURLConnection.setFollowRedirects(true);
}
/**
* Add a database
*
* @param databaseName database
* @throws Exception
*/
public void addDatabase(String databaseName) throws Exception {
if (log.isInfoEnabled())
log.info("Adding database " + databaseName);
dbServer.addDatabase(databaseName);
}
/**
* Get the update checker that checks for update to the core, extensions and
* loads the RSS feeds
*
* @return update checker
*/
public UpdateChecker getUpdateChecker() {
return updateChecker;
}
/**
* Add a {@link CoreScript} that will be made available on every page. Note,
* for the scripts to appear the theme must include the
* <strong>explorer:pageScripts</strong> tag.
*
* @param script script to add to all pages
*/
public void addPageScript(CoreScript script) {
pageScripts.add(script);
}
/**
* Remove a {@link CoreScript} from those made available on every page.
*
* @param script script to remove from all pages
*/
public void removePageScript(CoreScript script) {
pageScripts.remove(script);
}
/**
* Return a list of all the currently registered page scripts.
*
* @return list of page scripts
*/
public List getPageScripts() {
return pageScripts;
}
/**
* Return a command separated list of tiles configuration files that are
* currently in use.
*
* @return list of tiles configuration files
*/
public String getTilesConfigurationFiles() {
return tileConfigFiles.toString();
}
/**
* Add a {@link CoreListener} to the list of object that will be sent
* {@link CoreEvent}s.
*
* @param listener listener to add
*/
public void addCoreListener(CoreListener listener) {
coreListeners.add(CoreListener.class, listener);
}
/**
* Remove a {@link CoreListener} from the list of object that will be sent
* {@link CoreEvent}s.
*
* @param listener listener to remove
*/
public void removeCoreListener(CoreListener listener) {
coreListeners.remove(CoreListener.class, listener);
}
/**
* Fire a {@link CoreEvent} at all {@link CoreListener}s that have
* registered an interest in events.
*
* @param evt event to fire to all listener
*/
public void fireCoreEvent(CoreEvent evt) {
EventListener[] l = coreListeners.getListeners(CoreListener.class);
for (int i = l.length - 1; i >= 0; i--) {
/*
* We dont want badly behaved listeners to throw uncaught
* execeptions and upset other listeners
*/
try {
((CoreListener) l[i]).coreEvent(evt);
} catch (Throwable t) {
log.error("Event failed.", t);
}
}
}
/*
* (non-Javadoc)
*
* @see org.apache.struts.action.ActionServlet#initOther()
*/
protected void initOther() throws ServletException {
super.initOther();
// Automatically configure extensions for when running in dev.
// environment
autoConfigureDevExtensions();
// Intiailise notifier
initNotifier();
// Listen for core events
addCoreListener(new DefaultCoreListener());
// Initialise plugin manager
if (log.isInfoEnabled())
log.info("Creating extension manager.");
pluginManager = new PluginManager();
// pluginManager.setPluginClassLoader( getClass().getClassLoader());
/*
* Load the application store resources - these may be changed by the
* application store when new descriptors are loaded
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -