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.UserDatabaseManager; 36 import com.sslexplorer.core.actions.AuthenticatedDispatchAction; 37 import com.sslexplorer.core.forms.CoreForm; 38 import com.sslexplorer.security.AuthenticationScheme; 39 import com.sslexplorer.security.Constants; 40 import com.sslexplorer.security.InvalidLoginCredentialsException; 41 import com.sslexplorer.security.PasswordCredentials; 42 import com.sslexplorer.security.SessionInfo; 43 import com.sslexplorer.security.UserDatabase; 44 import com.sslexplorer.security.forms.PromptForSessionPasswordForm; 45 46 55 public class PromptForSessionPasswordDispatchAction extends AuthenticatedDispatchAction { 56 final static Log log = LogFactory.getLog(SetPasswordAction.class); 57 58 61 public PromptForSessionPasswordDispatchAction() { 62 super(); 63 } 64 65 73 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 74 HttpServletResponse response) throws Exception { 75 ((CoreForm) form).setReferer(CoreUtil.getReferer(request)); 76 ((PromptForSessionPasswordForm)form).setForwardTo(request.getParameter("forwardTo")); 77 ((PromptForSessionPasswordForm)form).setTarget(request.getParameter("target")); 78 ((PromptForSessionPasswordForm)form).setFolder(request.getParameter("folder")); 79 return mapping.findForward("display"); 80 } 81 82 92 public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 93 throws Exception { 94 PromptForSessionPasswordForm pfspf = (PromptForSessionPasswordForm) form; 95 AuthenticationScheme scheme = (AuthenticationScheme) getSessionInfo(request).getHttpSession().getAttribute(Constants.AUTH_SESSION); 96 try { 97 SessionInfo session = getSessionInfo(request); 98 UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(session.getUser().getRealm()); 99 String username = session.getUser().getPrincipalName(); 100 if (!udb.checkPassword(username, pfspf.getPassword())) { 101 throw new Exception ("Incorrect password."); 102 } 103 scheme.addCredentials(new PasswordCredentials(username, pfspf.getPassword().toCharArray())); 104 request.setAttribute(Constants.REQ_ATTR_FORWARD_TO, ((PromptForSessionPasswordForm)form).getForwardTo()); 105 request.setAttribute(Constants.REQ_ATTR_TARGET, ((PromptForSessionPasswordForm)form).getTarget()); 106 request.setAttribute(Constants.REQ_ATTR_FOLDER, ((PromptForSessionPasswordForm)form).getFolder()); 107 return mapping.findForward("redirect"); 108 } catch (InvalidLoginCredentialsException e) { 109 ActionMessages mesgs = new ActionMessages(); 110 mesgs.add(Globals.ERROR_KEY, new ActionMessage("promptForSessionPassword.invalidCredentials")); 111 saveErrors(request, mesgs); 112 return mapping.findForward("display"); 113 } 114 } 115 116 126 public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 127 throws Exception { 128 return new ActionForward(((CoreForm) form).getReferer(), true); 129 } 130 131 139 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 140 return SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 141 } 142 143 } | Popular Tags |