Author: markt
Date: Fri Jul  3 19:32:52 2015
New Revision: 1689072

URL: http://svn.apache.org/r1689072
Log:
extracted sending saved request
Patch by fjodorver

Modified:
    
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java

Modified: 
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java?rev=1689072&r1=1689071&r2=1689072&view=diff
==============================================================================
--- 
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java
 (original)
+++ 
tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/provider/modules/FormAuthModule.java
 Fri Jul  3 19:32:52 2015
@@ -105,13 +105,10 @@ public class FormAuthModule extends Tomc
             UnsupportedCallbackException {
         Request request = (Request) messageInfo.getRequestMessage();
         HttpServletResponse response = (HttpServletResponse) 
messageInfo.getResponseMessage();
-        // References to objects we will need later
-        Session session = null;
-        Principal principal = null;
 
         // Have we authenticated this user before but have caching disabled?
         if (!isCache()) {
-            session = request.getSessionInternal(true);
+            Session session = request.getSessionInternal(true);
             if (log.isDebugEnabled()) {
                 log.debug("Checking for reauthenticate in session " + session);
             }
@@ -128,10 +125,10 @@ public class FormAuthModule extends Tomc
                 if (!passwordCallback.getResult()) {
                     forwardToErrorPage(request, response);
                 }
-                principal = getPrincipal(passwordCallback);
+                Principal principal = getPrincipal(passwordCallback);
                 if (principal != null) {
                     session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
-                    if (!matchRequest(request)) {
+                    if (!isMatchingSavedRequest(request)) {
                         handlePrincipalCallbacks(clientSubject, principal);
                         return AuthStatus.SUCCESS;
                     }
@@ -145,36 +142,10 @@ public class FormAuthModule extends Tomc
         // Is this the re-submit of the original request URI after
         // successful
         // authentication? If so, forward the *original* request instead.
-        if (matchRequest(request)) {
-            session = request.getSessionInternal(true);
-            if (log.isDebugEnabled()) {
-                log.debug("Restore request from session '" + 
session.getIdInternal() + "'");
-            }
-            principal = (Principal) 
session.getNote(Constants.FORM_PRINCIPAL_NOTE);
-            handlePrincipalCallbacks(clientSubject, principal);
-
-            // If we're caching principals we no longer needgetPrincipal the
-            // username
-            // and password in the session, so remove them
-            if (isCache()) {
-                session.removeNote(Constants.SESS_USERNAME_NOTE);
-                session.removeNote(Constants.SESS_PASSWORD_NOTE);
-            }
-            if (restoreRequest(request, session)) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Proceed to restored request");
-                }
-                return AuthStatus.SUCCESS;
-            } else {
-                if (log.isDebugEnabled()) {
-                    log.debug("Restore of original request failed");
-                }
-                response.sendError(HttpServletResponse.SC_BAD_REQUEST);
-                return AuthStatus.FAILURE;
-            }
+        if (isMatchingSavedRequest(request)) {
+            return submitSavedRequest(clientSubject, request, response);
         }
 
-        // Acquire references to objects we will need to evaluate
         String contextPath = request.getContextPath();
         String requestURI = request.getDecodedRequestURI();
 
@@ -190,6 +161,37 @@ public class FormAuthModule extends Tomc
     }
 
 
+    private AuthStatus submitSavedRequest(Subject clientSubject, Request 
request,
+            HttpServletResponse response) throws IOException, 
UnsupportedCallbackException {
+        Session session = request.getSessionInternal(true);
+        if (log.isDebugEnabled()) {
+            log.debug("Restore request from session '" + 
session.getIdInternal() + "'");
+        }
+        Principal principal = (Principal) 
session.getNote(Constants.FORM_PRINCIPAL_NOTE);
+        handlePrincipalCallbacks(clientSubject, principal);
+
+        // If we're caching principals we no longer need getPrincipal the
+        // username
+        // and password in the session, so remove them
+        if (isCache()) {
+            session.removeNote(Constants.SESS_USERNAME_NOTE);
+            session.removeNote(Constants.SESS_PASSWORD_NOTE);
+        }
+        if (restoreRequest(request, session)) {
+            if (log.isDebugEnabled()) {
+                log.debug("Proceed to restored request");
+            }
+            return AuthStatus.SUCCESS;
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Restore of original request failed");
+            }
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+            return AuthStatus.FAILURE;
+        }
+    }
+
+
     /**
      * Save this request and redirect to the form login page
      *
@@ -467,7 +469,7 @@ public class FormAuthModule extends Tomc
      *
      * @param request The request to be verified
      */
-    protected boolean matchRequest(Request request) {
+    protected boolean isMatchingSavedRequest(Request request) {
         // Has a session been created?
         Session session = request.getSessionInternal(false);
         if (session == null) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to