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

📄 coreservlet.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        
        /* Install plugins. This is only done once after the extension containing
         * the plugin is installed
         */ 
        pluginManager.install();


        // Start the plugins
        if ("true".equalsIgnoreCase(System.getProperty("sslexplorer.disablePlugins"))) {
            log.warn("Extension manager disabled, extensions wont be started.");
        } else {
        	if (log.isInfoEnabled())
        		log.info("Starting extensions.");
            pluginManager.start();
        }

        // Register CONNECT handler
        if (!ContextHolder.getContext().isSetupMode()) {
            if(System.getProperty("sslexplorer.testing", "false").equals("true")) {
                ContextHolder.getContext().registerRequestHandler(new TestRequestHandler());
            }
            ContextHolder.getContext().registerRequestHandler(connectProxyMethodHandler);
            ContextHolder.getContext().registerRequestHandler(new ReverseProxyMethodHandler());
        }

        /**
         * Register security questions
         */

        try {
            CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
                new UserAttributeDefinition(PropertyDefinition.TYPE_STRING, "fathersFirstName", "", 4000, "securityQuestions", "",
                                UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE, 10, "security", false, "Father's First Name",
                                "", true, false));

            CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
                new UserAttributeDefinition(PropertyDefinition.TYPE_STRING, "placeOfBirth", "", 4000, "securityQuestions", "",
                                UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE, 20, "security", false, "Place of Birth", "",
                                true, false));

            CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
                new UserAttributeDefinition(PropertyDefinition.TYPE_STRING, "favoriteBook", "", 4000, "securityQuestions", "",
                                UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE, 30, "security", false, "Favorite Book", "",
                                true, false));

            CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
                new UserAttributeDefinition(PropertyDefinition.TYPE_STRING, "mothersMaidenName", "", 4000, "securityQuestions", "",
                                UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE, 40, "security", false, "Mother's Maiden Name",
                                "", true, false));

            CoreServlet.getServlet().getUserDatabase().registerUserAttributeDefinition(
                new UserAttributeDefinition(PropertyDefinition.TYPE_STRING, "favoriteTVShow", "", 4000, "securityQuestions", "",
                                UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE, 50, "security", false, "Favorite TV Show", "",
                                true, false));
        } catch (Exception e1) {
            log.error("Failed to register security questions attributes", e1);
        }

        // Start watching for version updates and RSS updates (if enabled)
        updateChecker.start();

        // Start the notifier
        try {
            notifier.start();
        } catch (Exception e) {
            log.error("Failed to start notifier.", e);
        }
    }

    protected void loadPropertyDatabase() throws Exception {

    	if (log.isInfoEnabled())
    		log.info("Loading property database");

        propertyDatabase = new JDBCPropertyDatabase();
        propertyDatabase.open(this);
        if (log.isInfoEnabled())
        	log.info("Loading property categories");
        XMLElement el = new XMLElement();
        InputStream in = getClass().getResourceAsStream("/com/sslexplorer/properties/categories.xml");
        if (in == null) {
            throw new IOException("Could not locate resource categories.xml");
        }
        try {
            el.parseFromReader(new InputStreamReader(in));
            addCategories(el, null);
        } finally {
            in.close();
        }

        // Add the context property definitions
        for (Iterator i = ContextHolder.getContext().getContextPropertyDefinitions().iterator(); i.hasNext();) {
            PropertyDefinition def = (PropertyDefinition) i.next();
            propertyDatabase.registerPropertyDefinition(def);
        }

        if (log.isInfoEnabled())
        	log.info("Property database loaded");
    }

    protected void addCategories(XMLElement el, PropertyDefinitionCategory parent) {
        PropertyDefinitionCategory cat = new DefaultPropertyDefinitionCategory(el.getIntAttribute("id"), el
                        .getStringAttribute("bundle"), el.getStringAttribute("image"));
        propertyDatabase.addPropertyDefinitionCategory(parent == null ? -1 : parent.getId(), cat);
        Vector c = el.getChildren();
        for (Iterator i = c.iterator(); i.hasNext();) {
            addCategories((XMLElement) i.next(), cat);
        }
    }

    protected void initNotifier() throws ServletException {

        File queueDir = new File(ContextHolder.getContext().getConfDirectory(), "queue");
        if (!queueDir.exists()) {
            if (!queueDir.mkdirs()) {
                throw new ServletException("Could not create message queue directory " + queueDir.getAbsolutePath());
            }
        }
        if (!queueDir.isDirectory()) {
            throw new ServletException("Message queue directory appears to not be a directory.");
        }
        if (!queueDir.canWrite() || !queueDir.canRead()) {
            throw new ServletException("Message queue directory " + queueDir.getAbsolutePath() + " has incorret permissions.");
        }
        try {
            notifier = new Notifier(queueDir);
        } catch (IOException e2) {
            log.error("Notifier failed to initialise.", e2);
            throw new ServletException(e2);
        }
        try {
            notifier.addSink(new SMTPMessageSink(), getPropertyDatabase().getPropertyBoolean(0, null, "smtp.startOnStartup"));
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServletException("Failed to add SMTP message sink.", e);
        }
        notifier.addSink(new VPNClientMessageSink(), true);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionServlet#initModuleMessageResources(org.apache.struts.config.ModuleConfig)
     */
    protected void initModuleMessageResources(final ModuleConfig config) throws ServletException {
        super.initModuleMessageResources(config);
        if (log.isInfoEnabled())
        	log.info("Initialising extension message resources");
        getServletContext().setAttribute("applicationStore" + config.getPrefix(), applicationStoreResources);
    }

    /**
     * There will only ever been one instance of the servlet, this method allows
     * static access to it.
     * 
     * @return the core servlet instance
     */
    public static CoreServlet getServlet() {
        return instance;
    }

    /**
     * Get the notifier instance that may be used to send notification messages
     * to users, adminstrators etc.
     * 
     * @return notifier
     */
    public Notifier getNotifier() {
        return notifier;
    }

    /**
     * Get the plugin manager instance.
     * 
     * @return plugin manager
     */
    public PluginManager getPluginManager() {
        return pluginManager;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.servlet.GenericServlet#init()
     */
    public void init() throws ServletException {
        
        ContextHolder.getContext().addContextListener(this);

        // Start the database
        // TODO this should be configurable
        try {
            dbServer = new EmbeddedHSQLDBServer("true".equalsIgnoreCase(System.getProperty("sslexplorer.hsqldb.tcpipServer",
                "false")));
        } catch (Exception e) {
            log.error("Failed to start the embedded database.", e);
            throw new ServletException("Failed to initialise embedded database.", e);
        }

        // Load the property database and categories
        try {
            loadPropertyDatabase();
        } catch (Exception e) {
            log.error("Failed to initialise property database.", e);
            throw new ServletException("Failed to initialise property database.", e);
        }

        super.init();

        fireCoreEvent(new CoreEvent(this, CoreEventConstants.SERVER_STARTED, null, null));
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionServlet#initModuleConfig(java.lang.String,
     *      java.lang.String)
     */
    protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {
        ModuleConfig config = super.initModuleConfig(prefix, paths);

        Digester digester = initConfigDigester();

        // Process each specified resource path
        while (paths.length() > 0) {
            digester.push(config);
            String path = null;
            int comma = paths.indexOf(',');
            if (comma >= 0) {
                path = paths.substring(0, comma).trim();
                paths = paths.substring(comma + 1);
            } else {
                path = paths.trim();
                paths = "";
            }

            if (path.length() < 1) {
                break;
            }

            this.parseModuleConfigFile(digester, path);
        }

        // Add the additional default struts configs

        digester.push(config);
        this.parseModuleConfigFile(digester, "/WEB-INF/wizard-struts-config.xml");
        digester.push(config);
        this.parseModuleConfigFile(digester, "/WEB-INF/ajax-struts-config.xml");
        
        /**
         * Install Maverick SSL support
         */
        try {
            if (log.isInfoEnabled())
                log.info("Installing Maverick SSL");
            com.maverick.ssl.https.HttpsURLStreamHandlerFactory.addHTTPSSupport();
        } catch (IOException ex1) {
            throw new ServletException("Failed to install Maverick SSL support");
        }
        boolean strictHostVerification = false;
        System.setProperty("com.maverick.ssl.allowUntrustedCertificates", String.valueOf(!strictHostVerification));
        System.setProperty("com.maverick.ssl.allowInvalidCertificates", String.valueOf(!strictHostVerification));
        
        if (log.isInfoEnabled())
            log.info("Adding default authentication modules.");
        // Add the default authentication modules
        AuthenticationModuleManager.getInstance().registerModule("Password", PasswordAuthenticationModule.class, "properties",
            true, true, false);
        AuthenticationModuleManager.getInstance().registerModule("HTTP", HTTPAuthenticationModule.class, "properties", true, true,
            false);
        AuthenticationModuleManager.getInstance().registerModule("PersonalQuestions", PersonalQuestionsAuthenticationModule.class,
            "properties", false, true, false);
        AuthenticationModuleManager.getInstance().registerModule("WebDAV", WebDAVAuthenticationModule.class, "properties", true,
            false, true);
        AuthenticationModuleManager.getInstance().registerModule("EmbeddedClient", EmbeddedClientAuthenticationModule.class,
            "properties", true, false, true);

        // Add the default page scripts
        addPageScript(new CoreScript(CoreScript.PAGE_HEADER, "JavaScript", "/js/prototype.js", null, "text/javascript"));
        addPageScript(new CoreScript(CoreScript.PAGE_HEADER, "JavaScript", "/js/scriptaculous.js", null, "text/javascript"));
        addPageScript(new CoreScript(CoreScript.PAGE_HEADER, "JavaScript", "/js/overlibmws.js", null, "text/javascript"));
        addPageScript(new CoreScript(CoreScript.PAGE_HEADER, "JavaScript", "/js/ajaxtags.js", null, "text/javascript"));
        addPageScript(new CoreScript(CoreScript.AFTER_BODY_START, "JavaScript", "/js/set.js", null, "text/javascript"));
        addPageScript(new CoreScript(CoreScript.AFTER_BODY_START, "JavaScript", "/js/windowManager.js", null, "text/javascript"));
        addPageScript(new CoreScript(CoreScript.BEFORE_BODY_END, "JavaScript", "/js/wz_tooltip.js", null, "text/javascript"));
        
        // Add the default panels
        PanelManager.getInstance().addPanel(new DefaultPanel("menu", Panel.SIDEBAR, 50, null, "menu"));
        PanelManager.getInstance().addPanel(new DefaultPanel("content", Panel.CONTENT, 50, null, "content"));
        PanelManager.getInstance().addPanel(new DefaultPanel("profileSelection", Panel.MESSAGES, 40, "/WEB-INF/jsp/tiles/profileSelection.jspf", null));
        PanelManager.getInstance().addPanel(new DefaultPanel("pageTasks", Panel.MESSAGES, 50, "/WEB-INF/jsp/tiles/pageTasks.jspf", "pageTasks"));
        PanelManager.getInstance().addPanel(new DefaultPanel("errorMessages", Panel.MESSAGES, 60, "/WEB-INF/jsp/tiles/errorMessages.jspf", null));
        PanelManager.getInstance().addPanel(new DefaultPanel("warnings", Panel.MESSAGES, 70, "/WEB-INF/jsp/tiles/warnings.jspf", null));
        PanelManager.getInstance().addPanel(new DefaultPanel("infoMessages", Panel.MESSAGES, 80, "/WEB-INF/jsp/tiles/infoMessages.jspf", null));
        PanelManager.getInstance().addPanel(new ClipboardPanel());
        PanelManager.getInstance().addPanel(new DefaultPanel("vpnClientErrors", Panel.MESSAGES, 100, "/WEB-INF/jsp/tiles/vpnClientErrors.jspf", null));
        PanelManager.getInstance().addPanel(new DefaultPanel("vpnClientMessages", Panel.MESSAGES, 110, "/WEB-INF/jsp/tiles/vpnClientMessages.jspf", null));
        PanelManager.getInstance().addPanel(new DefaultPanel("rssFeeds", Panel.MESSAGES, 120, "/WEB-INF/jsp/tiles/rssFeeds.jspf", null));
        PanelManager.getInstance().addPanel(new DefaultPanel("userSessions", Panel.STATUS_TAB , 10, "/WEB-INF/jsp/content/setup/userSessions.jspf", null, "setup"));
        PanelManager.getInstance().addPanel(new DefaultPanel("systemInfo", Panel.STATUS_TAB , 20, "/WEB-INF/jsp/content/setup/systemInfo.jspf", null, "setup"));
        
        // Add the default key store import types
        KeyStoreImportTypeManager.getInstance().registerType(new _3SPPurchaseImportType());

⌨️ 快捷键说明

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