📄 abstractresourcesdispatchaction.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.policyframework.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.sslexplorer.policyframework.NoPermissionException;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.ResourceType;
import com.sslexplorer.policyframework.ResourceUtil;
import com.sslexplorer.policyframework.forms.AbstractResourcesForm;
import com.sslexplorer.security.Constants;
import com.sslexplorer.table.actions.AbstractPagerAction;
public abstract class AbstractResourcesDispatchAction extends AbstractPagerAction {
protected Permission editPermission;
protected Permission createPermission;
protected Permission removePermission;
protected Permission assignPermission;
public AbstractResourcesDispatchAction() {
super();
}
public AbstractResourcesDispatchAction(ResourceType resourceType, Permission[] requiredPermissions,
Permission editPermission, Permission createPermission,
Permission removePermission, Permission assignPermission) {
this(resourceType, requiredPermissions, editPermission, createPermission, removePermission, assignPermission, null);
}
/**
* Constructor for normal resource types that have the standard,
* Create / Edit / Assign, Edit / Assign, Delete and Assign permissions
*
* @param resourceType resource type
* @param requiresResources requires actual resources of type
*/
public AbstractResourcesDispatchAction(ResourceType resourceType, ResourceType requiresResources) {
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, requiresResources);
}
public AbstractResourcesDispatchAction(ResourceType resourceType, Permission[] requiredPermissions,
Permission editPermission, Permission createPermission,
Permission removePermission, Permission assignPermission,
ResourceType requiresResources) {
super(resourceType, requiredPermissions, requiresResources);
this.editPermission = editPermission;
this.createPermission = createPermission;
this.removePermission = removePermission;
this.assignPermission = assignPermission;
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
return list(mapping, form, request, response);
}
public ActionForward confirmRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (getRemovePermission() != null) {
if (getResourceType() == null) {
throw new Exception(
"Concrete implementation of AbstractResourcesDispatchAction does not provide the ResourceType that it is maintaining.");
}
PolicyUtil.checkPermission(getResourceType(), getRemovePermission(), request);
}
return mapping.findForward("confirmRemove");
}
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (getCreatePermission() != null) {
if (getResourceType() == null) {
throw new Exception(
"Concrete implementation of AbstractResourcesDispatchAction does not provide the ResourceType that it is maintaining.");
}
PolicyUtil.checkPermission(getResourceType(), getCreatePermission(), request);
}
return mapping.findForward("create");
}
public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
Resource r= getResourceById(((AbstractResourcesForm)form).getSelectedResource());
checkValid(r, new Permission[] { getRemovePermission() }, mapping, (AbstractResourcesForm) form, request);
doRemove(mapping, form, request, response);
PolicyUtil.detachResourceFromPolicyList(r, getSessionInfo());
return mapping.findForward("refresh");
}
protected void doRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
getResourceType().removeResource(((AbstractResourcesForm)form).getSelectedResource(), getSessionInfo());
}
public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
edit(mapping, form, request, response);
return mapping.findForward("view");
}
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Get the selected resource ID and call the abstract getResourceById
// method to actual the actual resource object
int id = ((AbstractResourcesForm) form).getSelectedResource();
Resource r = getResourceById(id);
if (r == null) {
throw new Exception("No resource with ID " + id);
}
// Make sure this resource is one that is valid
checkValid(r, new Permission[] { getEditPermission(), getCreatePermission(), getAssignPermission() }, mapping, (AbstractResourcesForm) form, request);
request.getSession().setAttribute(Constants.EDITING_RESOURCE, r);
return mapping.findForward("edit");
}
public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("display");
}
public Resource getResourceById(int id) throws Exception {
return getResourceType().getResourceById(id);
}
protected void checkValid(Resource r, Permission[] permission, ActionMapping mapping, AbstractResourcesForm form, HttpServletRequest request)
throws NoPermissionException {
ResourceUtil.checkResourceManagementRights(r, this.getSessionInfo(), permission);
}
public Permission getEditPermission() {
return editPermission;
}
public Permission getAssignPermission() {
return assignPermission;
}
public Permission getCreatePermission() {
return createPermission;
}
public Permission getRemovePermission() {
return removePermission;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -