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

📄 webforwardform.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *  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.forms;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.core.BundleActionMessage;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.InterfacesMultiSelectListDataSource;
import com.sslexplorer.input.MultiSelectSelectionModel;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.forms.AbstractFavoriteResourceForm;
import com.sslexplorer.security.User;
import com.sslexplorer.webforwards.AbstractWebForward;
import com.sslexplorer.webforwards.ReplacementProxyWebForward;
import com.sslexplorer.webforwards.ReverseProxyWebForward;
import com.sslexplorer.webforwards.TunneledSiteWebForward;
import com.sslexplorer.webforwards.WebForward;
import com.sslexplorer.webforwards.WebForwardTypes;

/**
 * <p>
 * Form for providing the attributes to be edited and validated.
 * 
 * @author James D Robinson <a href="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
 * 
 */
public class WebForwardForm extends AbstractFavoriteResourceForm {
    static Log log = LogFactory.getLog(WebForwardForm.class);

    private String selectedTab = "details";
    private int type;
    private String destinationURL;
    private String category;

    // Replacement proxy attributes
    private PropertyList restrictToHosts;
    private String encoding;

    // Authenticating web forward
    private String authenticationUsername;
    private String authenticationPassword;
    private String preferredAuthenticationScheme;

    // Form based authentication
    private String formType;
    private String formParameters;

    // reverse proxy attribute
    private String paths;
    private boolean activeDNS;
    private String hostHeader;
    private Map customHeaders;

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
     *      javax.servlet.http.HttpServletRequest)
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errs = super.validate(mapping, request);
        if (isCommiting()) {
            if (getResourceName().equalsIgnoreCase("default")
                            && (!getEditing() || (getEditing() && !getResource().getResourceName().equalsIgnoreCase("default")))) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("error.createNetworkPlace.cantUseNameDefault"));
                setResourceName("");
            }
            try {
                if (!this.getDestinationURL().startsWith("#")){
                    // only chek the format if there is no hash on the front.
                    URL url = new URL(this.getDestinationURL());
                }
            } catch (MalformedURLException e) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.malformedURLException"));
            }
            
            if(getCategory().trim().equals("")) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("editWebForward.error.noCategory"));                
            }
            
            if (type == WebForward.TYPE_REVERSE_PROXY){
                if (!this.activeDNS && this.hostHeader.equals("")){
                    if (this.paths != null && this.paths.length() == 0){
                        errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.needs.path"));
                    }
                }
                if (!Boolean.parseBoolean(System.getProperty("sslexplorer.reverseProxyMutiplePaths", "false"))){
                    if (this.paths != null && this.paths.length() > 0){
                        StringTokenizer t = new StringTokenizer(this.paths, "\n\r");
                        while (t.hasMoreTokens()) {
                            String path = t.nextToken();
                            if (!path.startsWith("/")){
                                errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.invalidPath", path));
                            }
                            try {
                                if (CoreServlet.getServlet().getSystemDatabase().reverseProxyPathExists(path)){
                                    if (!CoreServlet.getServlet().getSystemDatabase().reverseProxyPathExists(path, this.getResourceId())){
                                        errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.duplicateReverseProxyPath", path));
                                    }
                                }
                            } catch (Exception e) {
                                errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.duplicateReverseProxyPathException"));
                            }
                        }
                    }
                }
            }
        }
        return errs;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.tabs.TabModel#getTabCount()
     */
    public int getTabCount() {
        if (type == WebForward.TYPE_TUNNELED_SITE){
            return 3;
        }
        else{
            return 4;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.tabs.TabModel#getTabName(int)
     */
    public String getTabName(int idx) {
        if (type == WebForward.TYPE_TUNNELED_SITE){
            switch (idx) {
                case 0:
                    return "details";
                case 1:
                    return "attributes";
                default:
                    return "policies";
            }
        }
        else{
            switch (idx) {
                case 0:
                    return "details";
                case 1:
                    return "attributes";
                case 2:
                    return "authentication";
                default:
                    return "policies";
            }

        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.policyframework.forms.AbstractResourceForm#initialise(com.sslexplorer.security.User,
     *      com.sslexplorer.boot.policyframework.Resource, boolean,
     *      com.sslexplorer.boot.MultiSelectSelectionModel,
     *      com.sslexplorer.boot.PropertyList, com.sslexplorer.security.User)
     */
    public void initialise(User user, Resource resource, boolean editing, MultiSelectSelectionModel policyModel,
                    PropertyList selectedPolicies, User owner) throws Exception {
        super.initialise(user, resource, editing, policyModel, selectedPolicies, owner);
        WebForward webForward = (WebForward) resource;

        this.type = webForward.getType();
        this.destinationURL = webForward.getDestinationURL();
        this.category = webForward.getCategory();

        if (this.type == WebForward.TYPE_REPLACEMENT_PROXY) {
            ReplacementProxyWebForward spwf = (ReplacementProxyWebForward) webForward;
            this.restrictToHosts = spwf.getRestrictToHosts();
            this.encoding = spwf.getEncoding();
            this.authenticationUsername = spwf.getAuthenticationUsername();
            this.authenticationPassword = spwf.getAuthenticationPassword();
            this.preferredAuthenticationScheme = spwf.getPreferredAuthenticationScheme();
            this.formParameters = spwf.getFormParameters();
            this.formType = spwf.getFormType();
        } else if (this.type == WebForward.TYPE_REVERSE_PROXY) {
            ReverseProxyWebForward rpwf = (ReverseProxyWebForward) webForward;
            this.paths = rpwf.getPaths();
            this.activeDNS = rpwf.getActiveDNS();
            this.customHeaders = rpwf.getCustomHeaders();
            this.authenticationUsername = rpwf.getAuthenticationUsername();
            this.authenticationPassword = rpwf.getAuthenticationPassword();
            this.preferredAuthenticationScheme = rpwf.getPreferredAuthenticationScheme();

⌨️ 快捷键说明

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