Author: markt
Date: Fri Jul  3 19:19:00 2015
New Revision: 1689068

URL: http://svn.apache.org/r1689068
Log:
Extracted principal callbacks handling
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=1689068&r1=1689067&r2=1689068&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:19:00 2015
@@ -132,11 +132,7 @@ public class FormAuthModule extends Tomc
                 if (principal != null) {
                     session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
                     if (!matchRequest(request)) {
-                        CallerPrincipalCallback principalCallback = new 
CallerPrincipalCallback(
-                                clientSubject, principal);
-                        GroupPrincipalCallback groupCallback = new 
GroupPrincipalCallback(
-                                clientSubject, 
context.getRealm().getRoles(principal));
-                        handler.handle(new Callback[] { principalCallback, 
groupCallback });
+                        handlePrincipalCallbacks(clientSubject, principal);
                         return AuthStatus.SUCCESS;
                     }
                 }
@@ -155,11 +151,7 @@ public class FormAuthModule extends Tomc
                 log.debug("Restore request from session '" + 
session.getIdInternal() + "'");
             }
             principal = (Principal) 
session.getNote(Constants.FORM_PRINCIPAL_NOTE);
-            CallerPrincipalCallback principalCallback = new 
CallerPrincipalCallback(clientSubject,
-                    principal);
-            GroupPrincipalCallback groupCallback = new 
GroupPrincipalCallback(clientSubject,
-                    realm.getRoles(principal));
-            handler.handle(new Callback[] { principalCallback, groupCallback 
});
+            handlePrincipalCallbacks(clientSubject, principal);
 
             // If we're caching principals we no longer needgetPrincipal the
             // username
@@ -190,7 +182,6 @@ public class FormAuthModule extends Tomc
         boolean loginAction = requestURI.startsWith(contextPath)
                 && requestURI.endsWith(Constants.FORM_ACTION);
 
-
         // No -- Save this request and redirect to the form login page
         if (!loginAction) {
             session = request.getSessionInternal(true);
@@ -304,6 +295,16 @@ public class FormAuthModule extends Tomc
     }
 
 
+    private void handlePrincipalCallbacks(Subject clientSubject, Principal 
principal)
+            throws IOException, UnsupportedCallbackException {
+        CallerPrincipalCallback principalCallback = new 
CallerPrincipalCallback(clientSubject,
+                principal);
+        GroupPrincipalCallback groupCallback = new 
GroupPrincipalCallback(clientSubject, context
+                .getRealm().getRoles(principal));
+        handler.handle(new Callback[] { principalCallback, groupCallback });
+    }
+
+
     private boolean isCache() {
         return true;
     }
@@ -343,7 +344,8 @@ public class FormAuthModule extends Tomc
      *             to {@link HttpServletResponse#sendError(int, String)} throws
      *             an {@link IOException}
      */
-    protected void forwardToLoginPage(Request request, HttpServletResponse 
response) throws IOException {
+    protected void forwardToLoginPage(Request request, HttpServletResponse 
response)
+            throws IOException {
 
         if (log.isDebugEnabled()) {
             log.debug(sm.getString("formAuthenticator.forwardLogin", 
request.getRequestURI(),



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

Reply via email to