📄 showaccountaction.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.security.actions;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
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.PropertyList;
import com.sslexplorer.core.CoreAttributeConstants;
import com.sslexplorer.core.CoreEvent;
import com.sslexplorer.core.CoreEventConstants;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.PublicKeyStore;
import com.sslexplorer.security.Role;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.User;
import com.sslexplorer.security.UserAttributeDefinition;
import com.sslexplorer.security.UserAttributeValueItem;
import com.sslexplorer.security.UserDatabase;
import com.sslexplorer.security.forms.UserAccountForm;
/**
* Implementation of {@link com.sslexplorer.core.actions.AuthenticatedDispatchAction}
* that allows an administrator to create or edit a user account.
* <p>
* If the current <i>User Database</i> does not support account creation then
* editing of the basic details is not allowed. The generic details such as
* 'enabled' and the user attributes may be changed.
*
* @author Brett Smith <a href="mailto: brett@3sp.com"><brett@3sp.com></a>
* @version $Revision: 1.54 $
*/
public class ShowAccountAction extends AuthenticatedDispatchAction {
/**
* Constructor.
*/
public ShowAccountAction() {
super(PolicyConstants.ACCOUNTS_RESOURCE_TYPE, new Permission[] {
PolicyConstants.PERM_CREATE,
PolicyConstants.PERM_EDIT,
PolicyConstants.PERM_DELETE
});
}
/* (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 {
request.getSession().removeAttribute(Constants.EDITING_ITEM);
return mapping.findForward("display");
}
/**
* Set the password.
*
* @param mapping mapping
* @param form form
* @param request request
* @param response response
* @return forward
* @throws Exception on any error
*/
public ActionForward setPassword(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
User user = CoreServlet.getServlet().getUserDatabase().getAccount(((UserAccountForm) form).getUsername());
request.getSession().setAttribute("setPassword.user", user);
return mapping.findForward("setPassword");
}
/**
* Create a new account.
*
* @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(PolicyConstants.ACCOUNTS_RESOURCE_TYPE, PolicyConstants.PERM_CREATE, request);
((UserAccountForm) form).initialize(null, false, request.getSession());
((UserAccountForm) form).setReferer(CoreUtil.getReferer(request));
CoreUtil.addRequiredFieldMessage(this, request);
return mapping.findForward("refresh");
}
/**
* Edit an existing account.
*
* @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(PolicyConstants.ACCOUNTS_RESOURCE_TYPE, PolicyConstants.PERM_EDIT, request);
String username = request.getParameter("username");
User user = CoreServlet.getServlet().getUserDatabase().getAccount(username);
((UserAccountForm) form).initialize(user, true, request.getSession());
((UserAccountForm) form).setReferer(CoreUtil.getReferer(request));
return mapping.findForward("display");
}
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
CoreUtil.addRequiredFieldMessage(this, request);
return mapping.findForward("display");
}
/**
* Commit the details to the user database.
*
* @param mapping mapping
* @param form form
* @param request request
* @param response response
* @return forward
* @throws Exception on any error
*/
public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserAccountForm account = (UserAccountForm) form;
PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_RESOURCE_TYPE, account.getEditing() ? PolicyConstants.PERM_EDIT : PolicyConstants.PERM_CREATE, request);
UserDatabase udb = CoreServlet.getServlet().getUserDatabase();
User user = null;
SessionInfo info = this.getSessionInfo();
if(udb.supportsAccountCreation()) {
PropertyList roleList = account.getRolesList();
int idx = 0;
Role[] roles = new Role[roleList.size()];
for(Iterator i = roleList.iterator(); i.hasNext(); ) {
roles[idx++] = udb.getRole((String)i.next());
}
if (account.getEditing()) {
user = udb.getAccount(account.getUsername());
try {
udb.updateAccount(user, account.getEmail(), account.getFullname(), roles, user.getAttributes());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -