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

📄 showauthenticationschemesdispatchaction.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.security.actions;

import java.util.Iterator;
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.boot.Util;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.PropertyUtil;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.policyframework.actions.AbstractResourcesDispatchAction;
import com.sslexplorer.security.AuthenticationSchemeSequence;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.forms.AuthenticationSchemesForm;

/**
 * Implementation of a
 * {@link com.sslexplorer.core.actions.AuthenticatedDispatchAction} that allows
 * an administrator to view, create, edit, delete and set default
 * <i>Authentication Schemes</i>.
 * 
 * @author Brett Smith <a href="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.25 $
 */
public class ShowAuthenticationSchemesDispatchAction extends AbstractResourcesDispatchAction {
    /**
     * Constructor
     */
    public ShowAuthenticationSchemesDispatchAction() {
        super(PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE, PolicyConstants.AUTHENTICATION_SCHEMES_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 {
        return list(mapping, form, request, response);
    }

    /**
     * Set the selected authentication scheme as the default.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward setAsDefault(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        PolicyUtil.checkPermission(PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE,
                        PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
        AuthenticationSchemesForm schemesForm = (AuthenticationSchemesForm) form;
        int id = schemesForm.getSelectedResource();
        AuthenticationSchemeSequence seq = (AuthenticationSchemeSequence) getResourceById(id);
        ActionMessages mesgs = new ActionMessages();
        if (seq.isSystemScheme()) {
            mesgs.add(Globals.ERROR_KEY, new ActionMessage("authenticationSchemes.error.cannotSetSystemSchemeAsDefault"));
            saveErrors(request, mesgs);
        } else {
            if (!seq.getEnabled()) {
                mesgs.add(Globals.ERROR_KEY, new ActionMessage("authenticationSchemes.error.cannotSetDisabledSchemeAsDefault"));
                saveErrors(request, mesgs);
            } else {
                PropertyUtil.getPropertyUtil().setProperty(0, null, "authenticationScheme.default", String.valueOf(id),
                                this.getSessionInfo());
                mesgs.add(Globals.ERROR_KEY, new ActionMessage("authenticationSchemes.message.defaultSet", seq.getResourceName()));
                saveMessages(request, mesgs);
            }
        }
        return list(mapping, form, request, response);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.policyframework.actions.AbstractResourcesDispatchAction#confirmRemove(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward confirmRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_DELETE, request);
        AuthenticationSchemesForm schemesForm = (AuthenticationSchemesForm) form;
        int id = schemesForm.getSelectedResource();
        int defaultScheme = CoreServlet.getServlet().getPropertyDatabase().getPropertyInt(0, null, "authenticationScheme.default");
        AuthenticationSchemeSequence seq = CoreServlet.getServlet().getSystemDatabase().getAuthenticationSchemeSequence(id);
        if (seq == null) {
            throw new Exception("No scheme with Id of " + id + ".");
        }
        if (seq.isSystemScheme()) {
            throw new Exception("Cannot remove system schemes.");
        }
        ActionMessages mesgs = new ActionMessages();
        if (defaultScheme == id) {
            List allSchemes = CoreServlet.getServlet().getSystemDatabase().getAuthenticationSchemeSequences();
            int nextEnabled = -1;
            for (Iterator i = allSchemes.iterator(); i.hasNext();) {
                AuthenticationSchemeSequence oseq = (AuthenticationSchemeSequence) i.next();
                if (!oseq.equals(seq) && oseq.getEnabled()) {
                    nextEnabled = oseq.getResourceId();
                }
            }
            if (nextEnabled == -1) {
                mesgs.add(Globals.ERROR_KEY, new ActionMessage("authenticationSchemes.error.mustHaveOneEnabledScheme"));
                saveErrors(request, mesgs);
                return list(mapping, form, request, response);
            }
        }
        PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_DELETE, request);
        return mapping.findForward("confirmRemove");
    }

    /**
     * Delete the selected authentication scheme.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_DELETE, request);
        AuthenticationSchemesForm schemesForm = (AuthenticationSchemesForm) form;
        int id = schemesForm.getSelectedResource();
        int defaultScheme = CoreServlet.getServlet().getPropertyDatabase().getPropertyInt(0, null, "authenticationScheme.default");
        AuthenticationSchemeSequence seq = CoreServlet.getServlet().getSystemDatabase().getAuthenticationSchemeSequence(id);
        if (seq == null) {
            throw new Exception("No scheme with Id of " + id + ".");
        }

⌨️ 快捷键说明

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