showuserattributedefinitionsdispatchaction.java
来自「这是linux下ssl vpn的实现程序」· Java 代码 · 共 195 行
JAVA
195 行
/*
* 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.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.policyframework.Permission;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.UserAttributeDefinition;
import com.sslexplorer.security.forms.UserAttributeDefinitionsForm;
import com.sslexplorer.table.actions.AbstractPagerAction;
/**
* Implementation of a
* {@link com.sslexplorer.table.actions.AbstractPagerAction} that allows
* an administrator to create, edit and delete <i>User Attribute Definitions</i>.
*
* @author Brett Smith <a href="mailto:brett@3sp.com"><brett@3sp.com></a>
* @version $Revision: 1.2 $
* @see com.sslexplorer.security.UserAttributeDefinition
*/
public class ShowUserAttributeDefinitionsDispatchAction extends AbstractPagerAction {
/**
* Constructor
*/
public ShowUserAttributeDefinitionsDispatchAction() {
super(PolicyConstants.USER_ATTRIBUTE_DEFINITIONS_RESOURCE_TYPE, new Permission[] { PolicyConstants.PERM_MAINTAIN } );
}
/*
* (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);
}
/**
* Confirm removal of the selected user attribute definition.
*
* @param mapping mapping
* @param form form
* @param request request
* @param response response
* @return forward
* @throws Exception on any error
*/
public ActionForward confirmRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
UserAttributeDefinitionsForm schemesForm = (UserAttributeDefinitionsForm) form;
String name = schemesForm.getSelectedItem();
UserAttributeDefinition def = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinition(name);
if (def == null) {
throw new Exception("No user attribute definition with name of " + name + ".");
}
return mapping.findForward("confirmRemove");
}
/**
* Delete the selected user attribute definition.
*
* @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_MAINTAIN, request);
UserAttributeDefinitionsForm f = (UserAttributeDefinitionsForm) form;
String name = f.getSelectedItem();
UserAttributeDefinition def = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinition(name);
if (def == null) {
throw new Exception("No user attribute definition with name of " + name + ".");
}
CoreServlet.getServlet().getUserDatabase().deleteUserAttributeDefinition(name);
ActionMessages msgs = new ActionMessages();
msgs.add(Globals.MESSAGE_KEY, new ActionMessage("userAttributeDefinitions.message.definitionDeleted", name));
saveMessages(request, msgs);
return mapping.findForward("refresh");
}
/**
* Edit the selected user attribute definition.
*
* @param mapping mapping
* @param form form
* @param request request
* @param response response
* @return forward
* @throws Exception on any error
*/
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
UserAttributeDefinitionsForm f = (UserAttributeDefinitionsForm) form;
String name = f.getSelectedItem();
UserAttributeDefinition def = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinition(name);
if (def == null) {
throw new Exception("No user attribute definition with name of " + name + ".");
}
request.getSession().setAttribute(
Constants.EDITING_ITEM, def);
return mapping.findForward("edit");
}
/**
* Create a new user attribute definition.
*
* @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 {
PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
return mapping.findForward("create");
}
/**
* List the authentication schemes configured.
*
* @param mapping mapping
* @param form form
* @param request request
* @param response response
* @return forward
* @throws Exception on any error
*/
public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
UserAttributeDefinitionsForm f = (UserAttributeDefinitionsForm) form;
getResources(request);
List defs = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinitions();
f.initialize(request.getSession(), defs);
Util.noCache(response);
return mapping.findForward("display");
}
/*
* (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;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?