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

📄 abstractresourcedispatchaction.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.policyframework.actions;

import java.util.Iterator;
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.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
import com.sslexplorer.core.forms.CoreForm;
import com.sslexplorer.input.MultiSelectDataSource;
import com.sslexplorer.input.MultiSelectSelectionModel;
import com.sslexplorer.navigation.FavoriteResourceType;
import com.sslexplorer.policyframework.NoPermissionException;
import com.sslexplorer.policyframework.OwnedResource;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.Policy;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.ResourcePermissionGrantedPoliciesDatasource;
import com.sslexplorer.policyframework.ResourceType;
import com.sslexplorer.policyframework.ResourceUtil;
import com.sslexplorer.policyframework.forms.AbstractFavoriteResourceForm;
import com.sslexplorer.policyframework.forms.AbstractResourceForm;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.User;

/**
 * Abstract implementation of an
 * {@link com.sslexplorer.core.actions.AuthenticatedDispatchAction} that allows
 * viewing, editing and creating of
 * {@link com.sslexplorer.policyframework.Resource} implementations.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.26 $
 */
public abstract class AbstractResourceDispatchAction extends AuthenticatedDispatchAction {
    final static Log log = LogFactory.getLog(AbstractResourceDispatchAction.class);

    protected Permission editPermission;
    protected Permission createPermission;
    protected Permission removePermission;
    protected Permission assignPermission;

    /**
     * Constructor that places now restriction on permissions required or
     * resources required.
     */
    public AbstractResourceDispatchAction() {
        super();
    }

    /**
     * Constructor for normal resource types that have the standard,
     * Create / Edit / Assign, Edit / Assign, Delete and Assign permissions
     * 
     * @param resourceType resource type
     */
    public AbstractResourceDispatchAction(ResourceType resourceType) {
        this(resourceType, new Permission[] { PolicyConstants.PERM_EDIT_AND_ASSIGN, PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE, PolicyConstants.PERM_ASSIGN  },
                        PolicyConstants.PERM_EDIT_AND_ASSIGN, PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE,
                        PolicyConstants.PERM_ASSIGN);
    }

    /**
     * Constructor for specific cases
     * 
     * @param resourceType resource type of permissions required
     * @param requiredPermissions required permissions
     * @param editPermission required edit permission
     * @param createPermission required create permission
     * @param removePermission required remove permission
     * @param assignPermission required assign permission
     */
    public AbstractResourceDispatchAction(ResourceType resourceType, Permission[] requiredPermissions, Permission editPermission,
                                          Permission createPermission, Permission removePermission, Permission assignPermission) {
        super(resourceType, requiredPermissions);
        this.editPermission = editPermission;
        this.createPermission = createPermission;
        this.removePermission = removePermission;
        this.assignPermission = assignPermission;
    }

    /*
     * (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 {
        return create(mapping, form, request, response);
    }

    /**
     * Create a new instance of the resource. Not all resource types will
     * require this as creation is usually done through a wizard.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if (getCreateResourcePermission() != null) {
            if (getResourceType() == null) {
                throw new Exception(
                    "Concrete implementation of AbstractResourceDispatchAction does not provide the ResourceType that it is maintaining.");
            }
            PolicyUtil.checkPermission(getResourceType(), getCreateResourcePermission(), request);
        }
        request.getSession().setAttribute(Constants.EDITING_RESOURCE, createResource(mapping, form, request, response));
        ActionForward fwd = edit(mapping, form, request, response);
        ((AbstractResourceForm) form).setCreating();
        return fwd;
    }

    /**
     * If the resource supports creation using the edit screen (most dont, they
     * now use wizards) this method must return an instance of the support
     * resource. <code>null</code> should be returned if creation isn't
     * supported here
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return resource
     * @throws Exception on any error
     */
    public abstract Resource createResource(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception;

    /**
     * Commit the resource being edited.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception
     */
    public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        AbstractResourceForm resourceForm = (AbstractResourceForm) form;
        resourceForm.apply();
        Resource resource = resourceForm.getResource();
        if(resourceForm.getEditing()) {
            resource.getResourceType().updateResource(resource, getSessionInfo());
        }
        else {
            commitCreatedResource(mapping, resourceForm, request, response);
        }
        doUpdate(mapping, form, request, response);
        
        // Profiles are a special case that cannot have their policies changes
        if(resource.getResourceType() != PolicyConstants.PROFILE_RESOURCE_TYPE || !resource.getResourceName().equals("Default")) {
            PolicyUtil.attachResourceToPolicyList(resource, resourceForm.getSelectedPoliciesList(), getSessionInfo());
        }
        if (resource.getResourceType() instanceof FavoriteResourceType) {
            PolicyUtil.setResourceGlobalFavorite(resource, ((AbstractFavoriteResourceForm) resourceForm).isFavorite());
        }
        return cleanUpAndReturnToReferer(mapping, form, request, response);
    }

    /**
     * <p> Method to be overridden when extra work needs to be done on update, in its abstract form it does nothing.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     */
    protected void doUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{

⌨️ 快捷键说明

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