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.ActionErrors; 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 34 import com.sslexplorer.core.CoreAttributeConstants; 35 import com.sslexplorer.core.CoreEvent; 36 import com.sslexplorer.core.CoreEventConstants; 37 import com.sslexplorer.core.CoreServlet; 38 import com.sslexplorer.core.CoreUtil; 39 import com.sslexplorer.core.actions.AuthenticatedDispatchAction; 40 import com.sslexplorer.security.LogonControllerFactory; 41 import com.sslexplorer.security.PublicKeyStore; 42 import com.sslexplorer.security.SessionInfo; 43 import com.sslexplorer.security.UpdatePrivateKeyPassphraseException; 44 import com.sslexplorer.security.forms.UpdatePrivateKeyPassphraseForm; 45 46 57 public class UpdatePrivateKeyPassphraseDispatchAction extends AuthenticatedDispatchAction { 58 final static Log log = LogFactory.getLog(SetPasswordAction.class); 59 60 63 public UpdatePrivateKeyPassphraseDispatchAction() { 64 super(); 65 } 66 67 75 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 76 HttpServletResponse response) throws Exception { 77 return mapping.findForward("display"); 78 } 79 80 90 public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 91 throws Exception { 92 UpdatePrivateKeyPassphraseForm f = (UpdatePrivateKeyPassphraseForm) form; 93 94 if (f.isResetPrivateKey()){ 95 PublicKeyStore.getInstance().removeKeys(getSessionInfo(request).getUser().getPrincipalName()); 97 return cleanUpAndReturn(mapping, request, mapping.findForward("confirmReset")); 98 } 99 else{ 100 104 try { 105 PublicKeyStore.getInstance().verifyPrivateKey(getSessionInfo(request).getUser().getPrincipalName(), f.getOldPassphrase().toCharArray()); 106 } catch (UpdatePrivateKeyPassphraseException upkpe) { 107 ActionErrors errs = new ActionErrors(); 109 errs.add(Globals.ERROR_KEY, new ActionMessage("updatePrivateKeyPassphrase.error.incorrectPassphrase")); 110 saveErrors(request.getSession(), errs); 111 return mapping.getInputForward(); 112 } 113 114 117 PublicKeyStore.getInstance().changePrivateKeyPassphrase( 118 getSessionInfo(request).getUser().getPrincipalName(), 119 f.getOldPassphrase(), 120 new String (LogonControllerFactory.getInstance().getPasswordFromCredentials( 121 getSessionInfo(request).getCredentials()))); 122 return cleanUpAndReturn(mapping, request, mapping.findForward("success")); 123 } 124 } 125 126 private ActionForward cleanUpAndReturn(ActionMapping mapping, HttpServletRequest request, ActionForward af) { 127 CoreUtil.removePageInterceptListener(request.getSession(), "updatePrivateKeyPassphrase"); 128 131 CoreServlet.getServlet().fireCoreEvent( 132 new CoreEvent(this, CoreEventConstants.LOGON, getSessionInfo(request).getCredentials(), 133 getSessionInfo(request)).addAttribute(CoreAttributeConstants.EVENT_ATTR_IP_ADDRESS, 134 request.getRemoteAddr()).addAttribute(CoreAttributeConstants.EVENT_ATTR_HOST, 135 request.getRemoteHost())); 136 137 return af; 138 } 139 140 150 public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 151 throws Exception { 152 return mapping.findForward("cancel"); 153 } 154 155 163 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 164 return SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 165 } 166 167 } | Popular Tags |