1 19 20 package com.sslexplorer.security.actions; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 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 46 public class ShowChangePasswordAction extends AuthenticatedAction { 47 final static Log log = LogFactory.getLog(SetPasswordAction.class); 48 49 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 request, HttpServletResponse response) 58 throws Exception { 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 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 getReferer(HttpServletRequest 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 request, HttpServletResponse response) { 89 return SessionInfo.USER_CONSOLE_CONTEXT; 90 } 91 } | Popular Tags |