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

📄 webforwardfinishaction.java

📁 这是linux下ssl vpn的实现程序
💻 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.webforwards.webforwardwizard.actions;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.core.CoreAttributeConstants;
import com.sslexplorer.core.CoreEvent;
import com.sslexplorer.core.CoreEventConstants;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.policyframework.ResourceChangeEvent;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.webforwards.AbstractAuthenticatingWebForward;
import com.sslexplorer.webforwards.WebForward;
import com.sslexplorer.webforwards.WebForwardTypeItem;
import com.sslexplorer.webforwards.WebForwardTypes;
import com.sslexplorer.webforwards.webforwardwizard.forms.WebForwardAuthenticationDetailsForm;
import com.sslexplorer.webforwards.webforwardwizard.forms.WebForwardResourceDetailsForm;
import com.sslexplorer.webforwards.webforwardwizard.forms.WebForwardSpecificDetailsForm;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.WizardActionStatus;
import com.sslexplorer.wizard.actions.AbstractFinishWizardAction;
import com.sslexplorer.wizard.forms.AbstractWizardFinishForm;

/**
 * <p>
 * The final action in which the resource is created.
 * 
 * @author James D Robinson <a href="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
 * 
 */
public class WebForwardFinishAction extends AbstractFinishWizardAction {
    final static Log log = LogFactory.getLog(WebForwardFinishAction.class);

    /**
     * Constructor.
     */
    public WebForwardFinishAction() {
        super();
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        return SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                     HttpServletResponse response) throws Exception {
        List actionStatus = new ArrayList();
        AbstractWizardSequence seq = getWizardSequence(request);
        String name = (String) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_RESOURCE_NAME, null);
        String description = (String) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_RESOURCE_DESCRIPTION, null);
        boolean favorite = ((Boolean) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_FAVORITE, Boolean.FALSE)).booleanValue();

        int type = ((Integer) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_TYPE, new Integer(0))).intValue();
        String category = (String) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_CATEGORY, null);
        String destinationURL = (String) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_DESTINATION_URL, null);

        PropertyList restrictToHosts = ((PropertyList) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_RESTRICT_TO_HOSTS, null));
        String encodeing = (String) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_ENCODEING, "");

        String authenticationUsername = (String) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_AUTHENTICATION_USERNAME,
            null);
        String authenticationPassword = (String) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_AUTHENTICATION_PASSWORD,
            null);
        String preferredAuthenticationScheme = (String) seq.getAttribute(
            WebForwardAuthenticationDetailsForm.ATTR_PREFERRED_AUTHENTICATION_SCHEME, null);

        String paths = (String) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_PATHS, "");
        String hostHeader = (String) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_HOST_HEADER, "");
        boolean activeDNS = ((Boolean) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_ACTIVE_DNS, Boolean.FALSE))
                        .booleanValue();
        // Map customHeaders = (Map)
        // seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_CUSTOM_HEADERS,
        // new
        // HashMap());

        String formParameters = (String) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_FORM_PARAMETERS, "");
        String formType = (String) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_FORM_TYPE, "");

        int parentResourcePermission = 0; // TODO get the parent resource
        // permission
        WebForward webForward = null;
        try {
            try {
                Calendar now = Calendar.getInstance();

                if (type == WebForward.TYPE_TUNNELED_SITE) {
                    com.sslexplorer.webforwards.TunneledSiteWebForward sswf = new com.sslexplorer.webforwards.TunneledSiteWebForward(
                                    -1, destinationURL, name, description, category, parentResourcePermission, now, now);
                    webForward = CoreServlet.getServlet().getSystemDatabase().createWebForward(sswf);
                } else if (type == WebForward.TYPE_REPLACEMENT_PROXY) {
                    com.sslexplorer.webforwards.ReplacementProxyWebForward spwf = new com.sslexplorer.webforwards.ReplacementProxyWebForward(
                                    -1, destinationURL, name, description, category, authenticationUsername,
                                    authenticationPassword, preferredAuthenticationScheme, encodeing, restrictToHosts, formType,
                                    formParameters, parentResourcePermission, now, now);

                    AbstractAuthenticatingWebForward abstractAuthenticatingWebForward = (AbstractAuthenticatingWebForward) CoreServlet
                                    .getServlet().getSystemDatabase().createWebForward(spwf);
                    webForward = abstractAuthenticatingWebForward;
                } else if (type == WebForward.TYPE_REVERSE_PROXY) {
                    com.sslexplorer.webforwards.ReverseProxyWebForward rpwf = new com.sslexplorer.webforwards.ReverseProxyWebForward(
                                    -1, destinationURL, name, description, category, authenticationUsername,
                                    authenticationPassword, preferredAuthenticationScheme, formType, formParameters, paths,
                                    hostHeader, activeDNS, parentResourcePermission, now, now, encodeing);
                    AbstractAuthenticatingWebForward abstractAuthenticatingWebForward = (AbstractAuthenticatingWebForward) CoreServlet
                                    .getServlet().getSystemDatabase().createWebForward(rpwf);
                    webForward = abstractAuthenticatingWebForward;
                }

            } catch (Exception e) {
                throw e;
            }
            actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
                            "webForwardWizard.webForwardFinish.status.profileCreated"));
        } catch (Exception e) {
            log.error("Failed to create profile.", e);
            actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
                            "webForwardWizard.webForwardFinish.status.failedToCreateProfile", e.getMessage()));
        }
        // TODO do the attaching.
        if (webForward != null) {
            actionStatus.add(attachToPoliciesAndAddToFavorites("webForwardWizard.webForwardFinish", seq, webForward, favorite));
        }
        ((AbstractWizardFinishForm) form).setActionStatus(actionStatus);
        return super.unspecified(mapping, form, request, response);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.wizard.actions.AbstractFinishWizardAction#exit(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        return cancel(mapping, form, request, response);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.wizard.actions.AbstractWizardAction#createWizardSequence(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    protected AbstractWizardSequence createWizardSequence(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                                          HttpServletResponse response) throws Exception {
        throw new Exception("Cannot create sequence on this page.");
    }

}

⌨️ 快捷键说明

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