1 19 20 package com.sslexplorer.properties.attributes.actions; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 30 import org.apache.struts.action.ActionForm; 31 import org.apache.struts.action.ActionForward; 32 import org.apache.struts.action.ActionMapping; 33 34 import com.sslexplorer.boot.PropertyClass; 35 import com.sslexplorer.boot.PropertyClassManager; 36 import com.sslexplorer.boot.PropertyDefinition; 37 import com.sslexplorer.core.CoreUtil; 38 import com.sslexplorer.core.actions.AuthenticatedDispatchAction; 39 import com.sslexplorer.properties.Property; 40 import com.sslexplorer.properties.attributes.AttributeDefinition; 41 import com.sslexplorer.properties.attributes.AttributeValueItem; 42 import com.sslexplorer.properties.attributes.forms.UserAttributesForm; 43 import com.sslexplorer.properties.impl.userattributes.UserAttributeKey; 44 import com.sslexplorer.properties.impl.userattributes.UserAttributes; 45 import com.sslexplorer.security.SessionInfo; 46 import com.sslexplorer.security.User; 47 48 49 56 public class UserAttributesDispatchAction extends AuthenticatedDispatchAction { 57 58 61 public UserAttributesDispatchAction() { 62 super(); 63 } 64 65 68 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 69 HttpServletResponse response) throws Exception { 70 List <AttributeValueItem> a = new ArrayList <AttributeValueItem>(); 71 SessionInfo sessionInfo = getSessionInfo(request); 72 PropertyClass propertyClass = PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME); 73 for(PropertyDefinition d : propertyClass.getDefinitions()) { 74 AttributeDefinition def = (AttributeDefinition)d; 75 if(def.isHidden()) 76 continue; 77 if(def.getVisibility() == AttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE || 78 def.getVisibility() == AttributeDefinition.USER_VIEWABLE_ATTRIBUTE 79 || def.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) { 80 a.add(new AttributeValueItem(def, request, Property.getProperty(new UserAttributeKey(sessionInfo.getUser(), def.getName())))); 81 } 82 } 83 Collections.sort(a); 84 ((UserAttributesForm)form).initialize(a); 85 ((UserAttributesForm)form).setReferer(CoreUtil.getReferer(request)); 86 return mapping.findForward("display"); 87 } 88 89 99 public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 100 throws Exception { 101 List l = ((UserAttributesForm)form).getUserAttributeValueItems(); 102 SessionInfo sessionInfo = getSessionInfo(request); 103 User u = sessionInfo.getUser(); 104 for(Iterator i = l.iterator(); i.hasNext(); ) { 105 AttributeValueItem item = (AttributeValueItem)i.next(); 106 if(item.getDefinition().getVisibility() == AttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE || 107 item.getDefinition().getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) { 108 Property.setProperty(new UserAttributeKey(u.getPrincipalName(), item.getDefinition().getName(), u.getRealm() 109 .getResourceId()), item.getDefinition().formatAttributeValue(item.getValue()), sessionInfo); 110 } 111 } 112 sessionInfo.setUser(u); 113 return cleanUpAndReturnToReferer(mapping, form, request, response); 114 } 115 116 119 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 120 return SessionInfo.USER_CONSOLE_CONTEXT; 121 } 122 123 133 public ActionForward resetUserAttributes(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 134 throws Exception { 135 for(Iterator i = ((UserAttributesForm)form).getUserAttributeValueItems().iterator(); i.hasNext(); ) { 136 AttributeValueItem v = (AttributeValueItem)i.next(); 137 v.setValue(v.getDefinition().parseValue(v.getDefinition().getDefaultValue())); 138 } 139 return mapping.findForward("display"); 140 } 141 } | Popular Tags |