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

📄 showprofilesdispatchaction.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.properties.actions;

import java.util.List;

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

import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.policyframework.NoPermissionException;
import com.sslexplorer.policyframework.OwnedResource;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.ResourceUtil;
import com.sslexplorer.policyframework.actions.AbstractResourcesDispatchAction;
import com.sslexplorer.policyframework.forms.AbstractResourcesForm;
import com.sslexplorer.properties.PropertyProfile;
import com.sslexplorer.properties.forms.ProfilesForm;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;

/**
 * This dispatch action is used for display and maintaing lists of property
 * profiles. Property profiles are the one type of resource in SSL-Explorer that
 * still has a 'scope', i.e. Personal Profiles may still be created.
 * 
 * @author Brett Smith <brett@3sp.com>
 */

public class ShowProfilesDispatchAction extends AbstractResourcesDispatchAction {

    /**
     * Constructor
     */
    public ShowProfilesDispatchAction() {
        super(PolicyConstants.PROFILE_RESOURCE_TYPE, PolicyConstants.PROFILE_RESOURCE_TYPE);
    }

    /*
     * (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 {
        ActionForward fwd = super.unspecified(mapping, form, request, response);
        ProfilesForm profilesForm = (ProfilesForm) form;
        SessionInfo session = this.getSessionInfo();
        List globalProfiles = null;
        List personalProfiles = null;
        if (session.getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
            profilesForm.setProfileScope(Constants.SCOPE_GLOBAL);
            globalProfiles = ResourceUtil.filterManageableResources(CoreServlet.getServlet().getPropertyDatabase().getPropertyProfiles(null,
                true), session.getUser());
        } else {
            profilesForm.setProfileScope(Constants.SCOPE_PERSONAL);
            globalProfiles = ResourceUtil.filterOwned(ResourceUtil.getGrantedResource(
                            getSessionInfo(), getResourceType()));            
            personalProfiles = ResourceUtil.filterResources(session.getUser(), CoreServlet.getServlet().getPropertyDatabase().getPropertyProfiles(
                session.getUser().getPrincipalName(), true), false);
        }
        PropertyProfile profile = (PropertyProfile) request.getSession().getAttribute(Constants.SELECTED_PROFILE);
        if (profile != null){
            profilesForm.initialize(globalProfiles, personalProfiles, request.getSession(), profile.getResourceId());
        }
        else{
            profilesForm.initialize(globalProfiles, personalProfiles, request.getSession(), -1);
        }
        return fwd;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.policyframework.actions.AbstractResourcesDispatchAction#create(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        if(getSessionInfo().getNavigationContext() == SessionInfo.USER_CONSOLE_CONTEXT) {
            PolicyUtil.checkPermission(PolicyConstants.PERSONAL_PROFILE_RESOURCE_TYPE, PolicyConstants.PERM_MAINTAIN, request);
        }
        else {
            return super.create(mapping, form, request, response);
        }
        return mapping.findForward("create");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.policyframework.actions.AbstractResourcesDispatchAction#remove(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        ProfilesForm f = (ProfilesForm) form;
        ActionMessages errors = new ActionMessages();
        PropertyProfile profile = (PropertyProfile) getResourceById(f.getSelectedResource());
        if (profile == null) {
            throw new Exception("Selected profile '" + f.getSelectedResource() + "' doesn't exist.");
        }
        if (profile.getOwnerUsername() == null && Constants.SCOPE_PERSONAL.equals(f.getProfileScope())) {
            errors.add(Globals.ERROR_KEY, new ActionMessage("error.deleteProfile.cantDeleteGlobalProfile"));
        }
        if (profile.getResourceName().equalsIgnoreCase("Default")
                        && (profile.getOwnerUsername() == null || profile.getOwnerUsername().equals(""))) {
            errors.add(Globals.ERROR_KEY, new ActionMessage("error.deleteProfile.cantDeleteDefaultProfile"));
        }
        saveErrors(request, errors);
        CoreUtil.resetMainNavigation(request.getSession());
        if (errors.size() > 0) {
            String returnTo = request.getParameter("returnTo");
            return returnTo != null ? new ActionForward(returnTo, false) : mapping.getInputForward();
        } else {
            return super.remove(mapping, form, request, response);
        }
    }

    /**
     * Dispatch action target called when the user wishes to select a profile.
     * After checking if the user has access, the profile will be made the
     * current profile for the session.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward select(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        ProfilesForm f = (ProfilesForm) form;
        PropertyProfile profile = CoreServlet.getServlet().getPropertyDatabase().getPropertyProfile(f.getSelectedResource());
        SessionInfo session = getSessionInfo();
        ResourceUtil.checkResourceAccessRights(profile, session);
        request.getSession().setAttribute(Constants.SELECTED_PROFILE, profile);
        ActionMessages messages = new ActionMessages();
        messages.add(Globals.MESSAGES_KEY, new ActionMessage("message.profileSelected", profile.getResourceName()));
        saveMessages(request, messages);
        return mapping.findForward("refresh");
    }

    /**
     * An alternative method of selecting a profile, this one forwards to
     * 'selectPropertyProfile' which also allows the selected to be chosen as a
     * default
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward selectOrDefault(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        return mapping.findForward("selectOrDefault");
    }

    /*
     * (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.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
    }

    protected void checkValid(Resource r, Permission[] permission, ActionMapping mapping, AbstractResourcesForm form, HttpServletRequest request) throws NoPermissionException {
        if(r instanceof OwnedResource && ((OwnedResource)r).getOwnerUsername() != null) {
            super.checkValid(r, new Permission[] { PolicyConstants.PERM_MAINTAIN } , mapping, form, request);            
        }
        else {
            super.checkValid(r, permission, mapping, form, request);
        }
    }
}

⌨️ 快捷键说明

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