tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1743019 - in /tomcat/trunk: java/org/apache/catalina/authenticator/AuthenticatorBase.java java/org/apache/catalina/authenticator/jaspic/CallbackHandlerImpl.java webapps/docs/changelog.xml
Date Mon, 09 May 2016 18:18:06 GMT
Author: markt
Date: Mon May  9 18:18:05 2016
New Revision: 1743019

URL: http://svn.apache.org/viewvc?rev=1743019&view=rev
Log:
Ensure that JASPIC's CallbackHandler is thread-safe.

Modified:
    tomcat/trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java
    tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/CallbackHandlerImpl.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java?rev=1743019&r1=1743018&r2=1743019&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java Mon May  9
18:18:05 2016
@@ -455,7 +455,7 @@ public abstract class AuthenticatorBase
             messageInfo = new MessageInfoImpl(request.getRequest(), response.getResponse(),
true);
             try {
                 ServerAuthConfig serverAuthConfig = jaspicProvider.getServerAuthConfig(
-                        "HttpServlet", jaspicAppContextID, new CallbackHandlerImpl());
+                        "HttpServlet", jaspicAppContextID, CallbackHandlerImpl.getInstance());
                 String authContextID = serverAuthConfig.getAuthContextID(messageInfo);
                 serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null,
null);
             } catch (AuthException e) {
@@ -1058,7 +1058,7 @@ public abstract class AuthenticatorBase
             ServerAuthContext serverAuthContext;
             try {
                 ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet",
-                        jaspicAppContextID, new CallbackHandlerImpl());
+                        jaspicAppContextID, CallbackHandlerImpl.getInstance());
                 String authContextID = serverAuthConfig.getAuthContextID(messageInfo);
                 serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null,
null);
                 serverAuthContext.cleanSubject(messageInfo, client);

Modified: tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/CallbackHandlerImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/CallbackHandlerImpl.java?rev=1743019&r1=1743018&r2=1743019&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/CallbackHandlerImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/authenticator/jaspic/CallbackHandlerImpl.java Mon
May  9 18:18:05 2016
@@ -34,19 +34,40 @@ import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
 
+/**
+ * Implemented as a singleton since the class is stateless.
+ */
 public class CallbackHandlerImpl implements CallbackHandler {
 
     private static final Log log = LogFactory.getLog(CallbackHandlerImpl.class);
     private static final StringManager sm = StringManager.getManager(CallbackHandlerImpl.class);
 
-    private String name;
-    private Principal principal;
-    private Subject subject;
-    private String[] groups;
+    private static CallbackHandler instance;
+
+
+    static {
+        instance = new CallbackHandlerImpl();
+    }
+
+
+    public static CallbackHandler getInstance() {
+        return instance;
+    }
+
+
+    private  CallbackHandlerImpl() {
+        // Hide default constructor
+    }
 
 
     @Override
     public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
+
+        String name = null;
+        Principal principal = null;
+        Subject subject = null;
+        String[] groups = null;
+
         if (callbacks != null) {
             // Need to combine data from multiple callbacks so use this to hold
             // the data
@@ -67,7 +88,7 @@ public class CallbackHandlerImpl impleme
             }
 
             // Create the GenericPrincipal
-            Principal gp = getPrincipal();
+            Principal gp = getPrincipal(principal, name, groups);
             if (subject != null && gp != null) {
                 subject.getPrivateCredentials().add(gp);
             }
@@ -75,12 +96,11 @@ public class CallbackHandlerImpl impleme
     }
 
 
-    private Principal getPrincipal() {
+    private Principal getPrincipal(Principal principal, String name, String[] groups) {
         // If the Principal is cached in the session JASPIC may simply return it
         if (principal instanceof GenericPrincipal) {
             return principal;
         }
-        String name = this.name;
         if (name == null && principal != null) {
             name = principal.getName();
         }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1743019&r1=1743018&r2=1743019&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon May  9 18:18:05 2016
@@ -213,6 +213,10 @@
         Do not trigger unnecessary session ID changes when using JASPIC and the
         user is authenticated using cached credentials. (markt)
       </fix>
+      <fix>
+        <bug>59437</bug>: Ensure that the JASPIC <code>CallbackHandler</code>
is
+        thread-safe. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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


Mime
View raw message