KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > actions > ShowSetPersonalAnswersAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security.actions;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc request, HttpServletResponse JavaDoc response)
61                     throws Exception JavaDoc {
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 JavaDoc<PersonalAnswer> personalAnswers = new ArrayList JavaDoc<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 JavaDoc id = PersonalQuestionsAuthenticationModule.SECURITY_QUESTIONS[i];
74             def = (AttributeDefinition)PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME).getDefinition(id);
75             String JavaDoc 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 JavaDoc request, HttpServletResponse JavaDoc response) {
90         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
91     }
92 }
Popular Tags