📄 userattributesdispatchaction.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.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
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 org.apache.struts.util.MessageResources;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.User;
import com.sslexplorer.security.UserAttributeDefinition;
import com.sslexplorer.security.UserAttributeValueItem;
import com.sslexplorer.security.forms.UserAttributesForm;
/**
* Implementation of {@link com.sslexplorer.core.actions.AuthenticatedDispatchAction}
* that displays and allows a user to change their user attributes.
*
* @author Brett Smith <a href="mailto: brett@3sp.com"><brett@3sp.com></a>
* @version $Revision: 1.7 $
* @see com.sslexplorer.security.UserAttributeDefinition
*/
public class UserAttributesDispatchAction extends AuthenticatedDispatchAction {
/**
* Constructor.
*/
public UserAttributesDispatchAction() {
super();
}
/* (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 {
List a = new ArrayList();
List l = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinitions();
for(Iterator i = l.iterator(); i.hasNext(); ) {
UserAttributeDefinition def = (UserAttributeDefinition)i.next();
if(def.getVisibility() == UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE ||
def.getVisibility() == UserAttributeDefinition.USER_VIEWABLE_ATTRIBUTE
|| def.getVisibility() == UserAttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
MessageResources mr = null;
if(def.getMessageResourcesKey() != null) {
mr = getResources(request, def.getMessageResourcesKey());
}
String value = def.getDefaultValue();
value = getSessionInfo().getUser().getAttributes().getProperty(def.getName(), value);
a.add(new UserAttributeValueItem(def, mr, value));
}
}
Collections.sort(a);
((UserAttributesForm)form).initialize(a);
((UserAttributesForm)form).setReferer(CoreUtil.getReferer(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 {
List l = ((UserAttributesForm)form).getUserAttributeValueItems();
User u = getSessionInfo().getUser();
for(Iterator i = l.iterator(); i.hasNext(); ) {
UserAttributeValueItem item = (UserAttributeValueItem)i.next();
if(item.getDefinition().getVisibility() == UserAttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE ||
item.getDefinition().getVisibility() == UserAttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
CoreUtil.setUserAttribute(getSessionInfo(), item.getDefinition(), item.getValue(), u);
}
}
CoreServlet.getServlet().getUserDatabase().updateAttributes(
u.getPrincipalName(), u.getAttributes());
// XXX HACK to ensure user attributes in memory are the same as persisted
getSessionInfo().setUser(u);
return cleanUpAndReturnToReferer(mapping, form, request, response);
}
/* (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.USER_CONSOLE_CONTEXT;
}
/**
* Reset all user attributes.
*
* @param mapping
* @param form
* @param request
* @param response
* @return forward
* @throws Exception
*/
public ActionForward resetUserAttributes(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
for(Iterator i = ((UserAttributesForm)form).getUserAttributeValueItems().iterator(); i.hasNext(); ) {
UserAttributeValueItem v = (UserAttributeValueItem)i.next();
v.setValue(v.getDefinition().getDefaultValue());
}
return mapping.findForward("display");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -