📄 showpropertyprofiledispatchaction.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.Calendar;
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.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.CoreEventConstants;
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.ResourceChangeEvent;
import com.sslexplorer.policyframework.ResourceUtil;
import com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction;
import com.sslexplorer.policyframework.forms.AbstractResourceForm;
import com.sslexplorer.properties.DefaultPropertyProfile;
import com.sslexplorer.properties.PropertyProfile;
import com.sslexplorer.properties.forms.PropertyProfileForm;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.User;
/**
* This dispatch action is responsible for allowing editing or creation of
* property profiles. Property profiles are the one resource in SSL-Explorer
* that still have 'scope', i.e. a user may create personal profiles.
* <p>
* Although this class could easily support it, creation of global profiles is
* now done through a wizard and thus a different action.
*
* @see com.sslexplorer.properties.PropertyProfile
* @see com.sslexplorer.properties.forms.PropertyProfileForm
* @author Brett Smith <brett@3sp.com>
*/
public class ShowPropertyProfileDispatchAction extends AbstractResourceDispatchAction {
final static Log log = LogFactory.getLog(ShowPropertyProfileDispatchAction.class);
/**
*
*/
public ShowPropertyProfileDispatchAction() {
super();
}
/* (non-Javadoc)
* @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#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 {
PolicyUtil.checkPermission(PolicyConstants.PROFILE_RESOURCE_TYPE, PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
}
request.getSession().setAttribute(Constants.EDITING_RESOURCE, createResource(mapping, form, request, response));
ActionForward fwd = edit(mapping, form, request, response);
((AbstractResourceForm) form).setCreating();
return fwd;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#createResource(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
public Resource createResource(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
/*
* Because only personal profiles are currently created using this
* action simple use the root resource permission as parent
*/
int resourcePermission = 0;
Calendar now = Calendar.getInstance();
return new DefaultPropertyProfile(0, CoreServlet.getServlet().getLogonController().getUser(request).getPrincipalName(), "",
"", resourcePermission, now, now);
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#edit(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
PropertyProfileForm pf = (PropertyProfileForm) form;
ActionForward fwd = super.edit(mapping, form, request, response);
String scope = pf.getOwner() == null ? Constants.SCOPE_GLOBAL : Constants.SCOPE_PERSONAL;
pf.setPropertyScope(scope);
SessionInfo session = CoreServlet.getServlet().getLogonController().getSessionInfo(request);
if (session.getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
pf.setPropertyProfiles(ResourceUtil.filterManageableResources(CoreServlet.getServlet().getPropertyDatabase()
.getPropertyProfiles(null, true), session.getUser()));
} else {
pf.setPropertyProfiles(ResourceUtil.filterResources(session.getUser(), CoreServlet.getServlet().getPropertyDatabase()
.getPropertyProfiles(session.getUser().getPrincipalName(), true), false));
}
return fwd;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#commit(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionMessages messages = new ActionMessages();
User user = CoreServlet.getServlet().getLogonController().getUser(request);
PropertyProfileForm profileForm = (PropertyProfileForm) form;
PropertyProfile profile = (PropertyProfile)profileForm.getResource();
if (profileForm.getPropertyScope().equals(Constants.SCOPE_GLOBAL)) {
PolicyUtil.checkPermission(PolicyConstants.PROFILE_RESOURCE_TYPE,
profileForm.getEditing() ? PolicyConstants.PERM_EDIT_AND_ASSIGN : PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
} else {
PolicyUtil.checkPermission(PolicyConstants.PERSONAL_PROFILE_RESOURCE_TYPE, PolicyConstants.PERM_MAINTAIN, request);
}
profileForm.apply();
int loadProfile = -1;
if (profileForm.getEditing()) {
PolicyUtil.attachResourceToPolicyList(profile, profileForm.getSelectedPoliciesList(), getSessionInfo());
profile.getResourceType().updateResource(profile, getSessionInfo());
} else {
int baseOn = profileForm.getSelectedPropertyProfile();
String username = "global".equals(profileForm.getPropertyScope()) ? null : user.getPrincipalName();
try {
PropertyProfile newProfile = CoreServlet.getServlet().getPropertyDatabase().createPropertyProfile(username,
profile.getResourceName(), profile.getResourceDescription(), baseOn,
profile.getParentResourcePermission());
PolicyUtil.attachResourceToPolicyList(newProfile, profileForm.getSelectedPoliciesList(), getSessionInfo());
loadProfile = newProfile.getResourceId();
} catch (Exception e) {
throw e;
}
}
messages.add(Globals.MESSAGES_KEY, new ActionMessage("message.profileSaved"));
saveMessages(request, messages);
ResourceUtil.setAvailableProfiles(request.getSession());
return cleanUpAndReturnToReferer(mapping, form, request, response);
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#display(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
public ActionForward display(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
((PropertyProfileForm) form).setReferer(CoreUtil.getReferer(request));
CoreUtil.addRequiredFieldMessage(this, request);
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 | SessionInfo.USER_CONSOLE_CONTEXT;
}
protected void checkValid(Resource r, Permission[] permissions, ActionMapping mapping, AbstractResourceForm 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, permissions, mapping, form, request);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -