1 19 20 package com.sslexplorer.security.actions; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.apache.struts.Globals; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.action.ActionMessage; 33 import org.apache.struts.action.ActionMessages; 34 35 import com.sslexplorer.boot.PropertyClassManager; 36 import com.sslexplorer.core.CoreUtil; 37 import com.sslexplorer.core.actions.AuthenticatedAction; 38 import com.sslexplorer.policyframework.Permission; 39 import com.sslexplorer.policyframework.PolicyConstants; 40 import com.sslexplorer.properties.Property; 41 import com.sslexplorer.properties.attributes.AttributeDefinition; 42 import com.sslexplorer.properties.impl.userattributes.UserAttributeKey; 43 import com.sslexplorer.properties.impl.userattributes.UserAttributes; 44 import com.sslexplorer.security.Constants; 45 import com.sslexplorer.security.LogonControllerFactory; 46 import com.sslexplorer.security.PersonalAnswer; 47 import com.sslexplorer.security.PersonalQuestionsAuthenticationModule; 48 import com.sslexplorer.security.SessionInfo; 49 import com.sslexplorer.security.User; 50 import com.sslexplorer.security.forms.PersonalAnswersForm; 51 52 public class ShowSetPersonalAnswersAction extends AuthenticatedAction { 53 54 public ShowSetPersonalAnswersAction() { 55 super(PolicyConstants.PERSONAL_DETAILS_RESOURCE_TYPE, new Permission[] { 56 PolicyConstants.PERM_CHANGE 57 }); 58 } 59 60 public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 61 throws Exception { 62 PersonalAnswersForm f = (PersonalAnswersForm) form; 63 if (CoreUtil.getPageInterceptListenerById(request.getSession(), "changePersonalAnswers") == null) { 64 if (f.getReferer() == null) { 65 f.setReferer(CoreUtil.getReferer(request)); 66 } 67 } 68 List <PersonalAnswer> personalAnswers = new ArrayList <PersonalAnswer>(); 69 User user = LogonControllerFactory.getInstance().getUser(request); 70 AttributeDefinition def; 71 for (int i = 0; i < PersonalQuestionsAuthenticationModule.SECURITY_QUESTIONS.length; i++) { 72 73 String id = PersonalQuestionsAuthenticationModule.SECURITY_QUESTIONS[i]; 74 def = (AttributeDefinition)PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME).getDefinition(id); 75 String answer = Property.getProperty(new UserAttributeKey(user, def.getName())); 76 personalAnswers.add(new PersonalAnswer(id, answer==null ? "" : answer, def.getLabel())); 77 } 78 79 f.initialize(personalAnswers); 80 if (request.getSession().getAttribute(Constants.REQ_ATTR_PERSONAL_ANSWERS_CHANGE_REASON_MESSAGE) != null) { 81 ActionMessages messages = new ActionMessages(); 82 messages.add(Globals.MESSAGE_KEY, (ActionMessage) request.getSession().getAttribute( 83 Constants.REQ_ATTR_PERSONAL_ANSWERS_CHANGE_REASON_MESSAGE)); 84 saveMessages(request, messages); 85 } 86 return mapping.findForward("display"); 87 } 88 89 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 90 return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT; 91 } 92 } | Popular Tags |