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

📄 networkplacefinishaction.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.vfs.wizards.actions;

import java.util.ArrayList;
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.PolicyUtil;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.ResourceChangeEvent;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.vfs.NetworkPlace;
import com.sslexplorer.vfs.NetworkPlaceResourceType;
import com.sslexplorer.vfs.webdav.DAVProcessor;
import com.sslexplorer.vfs.webdav.DAVServlet;
import com.sslexplorer.vfs.wizards.forms.DefaultNetworkPlaceDetailsForm;
import com.sslexplorer.vfs.wizards.forms.NetworkPlaceDetailsForm;
import com.sslexplorer.vfs.wizards.forms.NetworkPlacePolicySelectionForm;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.WizardActionStatus;
import com.sslexplorer.wizard.actions.AbstractWizardAction;
import com.sslexplorer.wizard.forms.AbstractWizardFinishForm;

/**
 * Implementation of {@link com.sslexplorer.wizard.actions.AbstractWizardAction}
 * that actually creates a <i>Network PLace</i> at the end of a wizard.
 * 
 * @author James D Robinson <a href="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
 * @version $Revision$
 */
public class NetworkPlaceFinishAction extends AbstractWizardAction {
    final static Log log = LogFactory.getLog(NetworkPlaceFinishAction.class);
    private NetworkPlace newNetworkPlace;

    /**
     * Constructor
     */
    public NetworkPlaceFinishAction() {
        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 {
        // Do the install
        List actionStatus = new ArrayList();
        AbstractWizardSequence seq = getWizardSequence(request);
        SessionInfo info = CoreServlet.getServlet().getLogonController().getSessionInfo(request);
        String scheme = (String) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_SCHEME, null);
        String shortName = (String) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_RESOURCE_NAME, null);
        String description = (String) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_RESOURCE_DESCRIPTION, null);
        String uri = (String) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_URI, null);
        if (uri.startsWith("\\\\")) {
            uri = "smb:" + uri.replace('\\', '/');
        }
        boolean favorite = ((Boolean) seq.getAttribute(DefaultNetworkPlaceDetailsForm.ATTR_FAVORITE, Boolean.FALSE)).booleanValue();
        boolean readOnly = ((Boolean) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_READ_ONLY, Boolean.FALSE)).booleanValue();
        boolean allowResursive = ((Boolean) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_ALLOW_RECURSIVE, Boolean.FALSE))
                        .booleanValue();
        boolean noDelete = ((Boolean) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_NO_DELETE, Boolean.FALSE)).booleanValue();
        boolean showHidden = ((Boolean) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_SHOW_HIDDEN, Boolean.FALSE)).booleanValue();
        DAVProcessor processor = DAVServlet.getDAVProcessor(request);
        int parentResourcePermission = ((Integer) seq.getAttribute(NetworkPlaceDetailsForm.ATTR_PARENT_RESOURCE_PERMISSION,
            new Integer(0))).intValue();
        // TODO get the resource permission that allowed this resource to be
        // created
        try {
            try {
                newNetworkPlace = processor.getRepository().createNetworkPlaceAndRegister(scheme, shortName, description, uri,
                    readOnly, allowResursive, noDelete, showHidden, info, parentResourcePermission);
            } catch (Exception e) {
                throw e;
            }
            actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
                            "networkPlaceWizard.networkPlaceFinish.status.profileCreated"));
        } catch (Exception e) {
            log.error("Failed to create profile.", e);
            actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
                            "networkPlaceWizard.networkPlaceFinish.status.failedToCreateProfile", e.getMessage()));
        }
        if (newNetworkPlace != null) {
            actionStatus.add(attachToPolicies(seq, newNetworkPlace, favorite));
        }
        ((AbstractWizardFinishForm) form).setActionStatus(actionStatus);
        return super.unspecified(mapping, form, request, response);
    }

    public NetworkPlace getNewNetworkPlace() {
        return newNetworkPlace;
    }

    /**
     * Exit the wizard
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        return cancel(mapping, form, request, response);
    }

    protected AbstractWizardSequence createWizardSequence(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                                          HttpServletResponse response) throws Exception {
        throw new Exception("Cannot create sequence on this page.");
    }

    WizardActionStatus attachToPolicies(AbstractWizardSequence seq, Resource resource, boolean addToFavorites) {
        PropertyList selectedPolicies = (PropertyList) seq.getAttribute(NetworkPlacePolicySelectionForm.ATTR_SELECTED_POLICIES,
            null);
        try {
            PolicyUtil.attachResourceToPolicyList(resource, selectedPolicies, getSessionInfo());
            PolicyUtil.setResourceGlobalFavorite(resource, addToFavorites);
            return new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
                            "networkPlaceWizard.networkPlaceFinish.status.attachedToPolicies");
        } catch (Exception e) {
            log.error("Failed to create profile.", e);
            return new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
                            "networkPlaceWizard.networkPlaceFinish.status.failedToAttachToPolicies", e.getMessage());
        }
    }

}

⌨️ 快捷键说明

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