KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.struts.Globals;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.struts.action.ActionMessage;
32 import org.apache.struts.action.ActionMessages;
33
34 import com.sslexplorer.core.CoreUtil;
35 import com.sslexplorer.core.actions.AuthenticatedAction;
36 import com.sslexplorer.policyframework.Permission;
37 import com.sslexplorer.policyframework.PolicyConstants;
38 import com.sslexplorer.properties.Property;
39 import com.sslexplorer.properties.impl.realms.RealmKey;
40 import com.sslexplorer.security.Constants;
41 import com.sslexplorer.security.SessionInfo;
42 import com.sslexplorer.security.forms.ChangePasswordForm;
43
44 /**
45  */

46 public class ShowChangePasswordAction extends AuthenticatedAction {
47     final static Log log = LogFactory.getLog(SetPasswordAction.class);
48
49     /**
50      */

51     public ShowChangePasswordAction() {
52         super(PolicyConstants.PASSWORD_RESOURCE_TYPE, new Permission[] {
53             PolicyConstants.PERM_CHANGE
54         });
55     }
56
57     public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
58                     throws Exception JavaDoc {
59         ChangePasswordForm f = (ChangePasswordForm) form;
60         ActionMessages messages = new ActionMessages();
61         if (request.getSession().getAttribute(Constants.PASSWORD_CHANGE_REASON_MESSAGE) != null) {
62             messages.add(Globals.MESSAGE_KEY, (ActionMessage) request.getSession().getAttribute(
63                 Constants.PASSWORD_CHANGE_REASON_MESSAGE));
64         }
65         try {
66             messages.add(Globals.MESSAGE_KEY, new ActionMessage("changePassword.message.passwordPolicy",
67                 Property
68                             .getProperty(new RealmKey("security.password.pattern.description", getSessionInfo(request).getUser()
69                                             .getRealm().getResourceId()))));
70         } catch (Exception JavaDoc e) {
71             log.error("Failed to get password policy text.", e);
72         }
73         f.setReferer(getReferer(request));
74         f.init(getSessionInfo(request).getUser().getPrincipalName());
75         saveMessages(request, messages);
76         CoreUtil.addRequiredFieldMessage(this, request);
77         return mapping.findForward("success");
78
79     }
80     
81     private static String JavaDoc getReferer(HttpServletRequest JavaDoc request) {
82         if(CoreUtil.isRefererInRequest(request)) {
83             return CoreUtil.getRequestReferer(request);
84         }
85         return CoreUtil.getReferer(request);
86     }
87
88     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
89         return SessionInfo.USER_CONSOLE_CONTEXT;
90     }
91 }
Popular Tags