⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coreservlet.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        messageResourcesFactory = new CoreMessageResourcesFactory(getClass().getClassLoader());
        applicationStoreResources = (CoreMessageResources) messageResourcesFactory
                        .createResources("com.sslexplorer.applications.store.ApplicationResources");
        applicationStoreResources.setReturnNull(false);

        // Initialise extension store
        ExtensionStore store = ExtensionStore.getInstance();

        // Initialise plugin
        try {
            store.init(ContextHolder.getContext().getApplicationDirectory(), new File(getServletContext().getRealPath(
                "/WEB-INF/client")));
            pluginManager.init();
        } catch (Exception e) {
            log.error("Failed to initialise plugin manager.", e);
            throw new ServletException(e);
        }

        boolean devConfig = "true".equalsIgnoreCase(System.getProperty("sslexplorer.useDevConfig", "false"));
        File defaultDevConfDir = new File(System.getProperty("user.dir"), "conf");
        try {
            if (devConfig
                            && ContextHolder.getContext().getConfDirectory().getCanonicalFile().equals(
                                defaultDevConfDir.getCanonicalFile())) {
                throw new ServletException("When running in developmenet mode, you may NOT use "
                                + defaultDevConfDir.getAbsolutePath() + " as your 'conf' directory. Please specifiy "
                                + "a different directory using the --conf=<dir> argument when starting the server.");
            }
        } catch (IOException ioe) {
            throw new ServletException("Failed to determine if incorrect conf directory is being used", ioe);
        }

        // Add the resource bases from the plugin
        if (!devConfig) {
            for (Iterator i = pluginManager.plugins(); i.hasNext();) {
                Plugin ex = (Plugin) i.next();
                PluginDefinition def = pluginManager.getPluginDefinition(ex);
                for (Iterator j = def.getResourceBases(); j.hasNext();) {
                    URL u = (URL) j.next();
                    List l = (List) resourceBases.get(ex);
                    if (l == null) {
                        l = new ArrayList();
                        resourceBases.put(ex, l);
                    }
                    l.add(u);
                    ContextHolder.getContext().addResourceBase(u);
                }
            }
        } else {
            log.warn("Not adding resource bases as SSL-Explorer is in development mode. Youll have to use the "
                            + " the sslexplorer.additionalWebResourceDirectories system property to specify "
                            + "the actual locations of plugin resource bases. You may also use sslexplorer.devExtensions.");
        }

        //
        String additionalWebResources = System.getProperty("sslexplorer.additionalWebResourceDirectories", "");
        if (additionalWebResources != null) {
            StringTokenizer t = new StringTokenizer(additionalWebResources, ",");
            while (t.hasMoreTokens()) {
                try {
                    URL u = null;
                    String dir = t.nextToken();
                    if (dir.endsWith("]")) {
                        int idx = dir.indexOf('[');
                        if (idx != -1) {
                            String pluginName = dir.substring(idx + 1, dir.length() - 1);
                            Plugin ex = pluginManager.getPlugin(pluginName);
                            dir = dir.substring(0, idx);
                            u = new File(dir).getCanonicalFile().toURL();
                            List l = (List) resourceBases.get(ex);
                            if (l == null) {
                                l = new ArrayList();
                                resourceBases.put(ex, l);
                            }
                            l.add(u);
                        }
                    }
                    if (u == null) {
                        u = new File(dir).getCanonicalFile().toURL();
                    }
                    ContextHolder.getContext().addResourceBase(u);
                } catch (Exception e) {
                    log.error("Failed to add additional web resources directory.", e);
                }
            }
        }

        //
        for (int i = 0; i < pluginManager.getPluginCount(); i++) {
            Plugin plugin = pluginManager.getPluginAt(i);
            if (!(plugin instanceof Plugin)) {
                log.error("Plugin " + plugin.getClass().getName() + " does not implement CoreExtension.");
            } else {
                Plugin ext = (Plugin) plugin;
                String tilesConfigFile = ext.getTilesConfigFile();
                if (tilesConfigFile != null) {
                    addTileConfigurationFile(tilesConfigFile);
                }
            }
        }

        // finally setup the scheduler
        this.getServletContext().setAttribute(StoppableTimer.NAME, new StoppableTimer());
    }

    /**
     * Set the {@link LogonController} implementation to use. If the
     * <code>lock</code> argument is specified, then subsequent attempts to
     * set a new logon controller will fail.
     * 
     * @param logonControllerClass class for logon controller implementation
     * @param lock lock the logon controll to this class
     * @throws IllegalStateException if previous caller specified lock
     */

    public void setLogonControllerClass(Class logonControllerClass, boolean lock) throws IllegalStateException {
        if (logonControllerLocked) {
            throw new IllegalStateException("Logon controller has been locked by another plugin.");
        }
        this.logonControllerClass = logonControllerClass;
        logonControllerLocked = lock;
    }

    /**
     * Set the class of system database to use.
     * 
     * @param systemDatabaseClass system database database class.
     */
    public void setSystemDatabaseClass(Class systemDatabaseClass) {
        this.systemDatabaseClass = systemDatabaseClass;
    }

    /**
     * Get the {@link CoreMessageResources} that contains all installed
     * extension message resource.
     * 
     * @return extension store message resources
     */
    public CoreMessageResources getExtensionStoreResources() {
        return applicationStoreResources;
    }

    /**
     * Get the struts module configuration object.
     * 
     * @return struts module config.
     */
    public ModuleConfig getModuleConfig() {
        return moduleConfig;
    }

    private void addTileConfigurationFile(String path) {
    	if (log.isInfoEnabled())
    		log.info("Adding tile configuration file " + path);
        if (tileConfigFiles.length() > 0)
            tileConfigFiles.append(',');
        tileConfigFiles.append(path);
    }

    private void removeTileConfigurationFile(String path) {
    	if (log.isInfoEnabled())
    		log.info("Removing tile configuration file " + path);
        // TODO Why on earth are we using a string to store the list of tile
        // config files?
        StringBuffer buf = new StringBuffer();
        StringTokenizer t = new StringTokenizer(tileConfigFiles.toString(), ",");
        while (t.hasMoreTokens()) {
            String p = t.nextToken();
            if (!p.equals(path)) {
                if (buf.length() > 0) {
                    buf.append(",");
                }
                buf.append(p);
            }
        }
        tileConfigFiles = buf;
        if (log.isInfoEnabled())
        	log.info("New tile configuration path is " + tileConfigFiles.toString());
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionServlet#initModulePlugIns(org.apache.struts.config.ModuleConfig)
     */
    protected void initModulePlugIns(ModuleConfig moduleConfig) throws ServletException {
        this.moduleConfig = moduleConfig;

        if (log.isDebugEnabled()) {
            log.debug("Initializing module path '" + moduleConfig.getPrefix() + "' plug ins");
        }

        PlugInConfig plugInConfigs[] = moduleConfig.findPlugInConfigs();
        PlugIn plugIns[] = new PlugIn[plugInConfigs.length];

        getServletContext().setAttribute(Globals.PLUG_INS_KEY + moduleConfig.getPrefix(), plugIns);
        for (int i = 0; i < plugIns.length; i++) {
            try {
                plugIns[i] = (PlugIn) RequestUtils.applicationInstance(plugInConfigs[i].getClassName());
                BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties());
                // Pass the current plugIn config object to the PlugIn.
                // The property is set only if the plugin declares it.
                // This plugin config object is needed by Tiles
                try {
                    PropertyUtils.setProperty(plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]);
                } catch (Exception e) {
                    // FIXME Whenever we fail silently, we must document a valid
                    // reason
                    // for doing so. Why should we fail silently if a property
                    // can't be set on
                    // the plugin?
                    /**
                     * Between version 1.138-1.140 cedric made these changes.
                     * The exceptions are caught to deal with containers
                     * applying strict security. This was in response to bug
                     * #15736
                     * 
                     * Recommend that we make the currentPlugInConfigObject part
                     * of the PlugIn Interface if we can, Rob
                     */
                }
                plugIns[i].init(this, moduleConfig);

            } catch (ServletException e) {
                throw e;
            } catch (Exception e) {
                String errMsg = internal.getMessage("plugIn.init", plugInConfigs[i].getClassName());

                log(errMsg, e);
                throw new UnavailableException(errMsg);
            }
        }

        
        // Create the CONNECT handler (Logon Controller will need it) - this
        // will be registered after the plugins tho
        connectProxyMethodHandler = new ConnectRequestHandler();
        // Use the default logon controller if no other has been registered
        try {
            if (logonControllerClass == null) {
                logonControllerClass = Class.forName("com.sslexplorer.security.DefaultLogonController");
            }
            logonController = (LogonController) logonControllerClass.newInstance();
            logonController.init();
        } catch (Exception e) {
            log.error("Failed to initialise logon controller.", e);
            throw new ServletException("Failed to initialise logon controller." + e.getMessage(), e);
        }

        // Use the default system database if no other has been registered
        try {
            if (systemDatabaseClass == null) {
                systemDatabaseClass = Class.forName("com.sslexplorer.jdbc.JDBCSystemDatabase");
            }
            systemDatabase = (SystemDatabase) systemDatabaseClass.newInstance();
            systemDatabase.open(this);
        } catch (Exception e) {
            log.error("Failed to initialise system database.", e);
            throw new ServletException("Failed to initialise system database.", e);
        }

        // Configure policy database
        try {
            if (policyDatabaseClass == null) {
                policyDatabaseClass = Class.forName("com.sslexplorer.jdbc.JDBCPolicyDatabase");
            }
            policyDatabase = (PolicyDatabase) policyDatabaseClass.newInstance();
            policyDatabase.open(this);
        } catch (Exception e) {
            log.error("Failed to initialise policy database.", e);
            throw new ServletException("Failed to initialise policy database.", e);
        }

        // Configure user database

        try {
            userDatabase = UserDatabaseManager.getInstance().getUserDatabase(
                getPropertyDatabase().getProperty(0, null, "security.userDatabase"));
            userDatabase.open(this);
        }
        catch(Throwable t) {
            if (!ContextHolder.getContext().isSetupMode()) {
                log.warn(t.getMessage(), t);
                throw new ServletException("Failed to initialise user database.", t);
            }            
            else {
                log.warn(t.getMessage() + ". Falling back to built-in user database.", t);
                try {
                    userDatabase = UserDatabaseManager.getInstance().getUserDatabase("builtIn");
                    userDatabase.open(this);
                }
                catch(Throwable t2) {
                    log.warn("Built-in user database failed to initialise too. Something is very wrong!", t2);
                    throw new ServletException("Failed to initialise configure user database or built-in as a fallback.", t);                    
                }
                
            }
        }

        try {
            policyDatabase.initResourcePermissions();
        } catch (Exception e1) {
            throw new ServletException("Failed to initialise resource permissions.");
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -