Author: rakeshr
Date: Wed Mar  2 06:47:30 2016
New Revision: 1733222

URL: http://svn.apache.org/viewvc?rev=1733222&view=rev
Log:
ZOOKEEPER-2375: Prevent multiple initialization of login object in each 
ZooKeeperSaslClient instance (yuemeng via rakeshr)

Modified:
    zookeeper/branches/branch-3.5/CHANGES.txt
    
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java

Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1733222&r1=1733221&r2=1733222&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Wed Mar  2 06:47:30 2016
@@ -102,6 +102,9 @@ BUGFIXES:
 
   ZOOKEEPER-2243: Supported platforms is completely out of date (cnauroth)
 
+  ZOOKEEPER-2375: Prevent multiple initialization of login object in each
+  ZooKeeperSaslClient instance (yuemeng via rakeshr)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-2270: Allow MBeanRegistry to be overridden for better unit tests

Modified: 
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
URL: 
http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java?rev=1733222&r1=1733221&r2=1733222&view=diff
==============================================================================
--- 
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
 (original)
+++ 
zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
 Wed Mar  2 06:47:30 2016
@@ -214,17 +214,21 @@ public class ZooKeeperSaslClient {
         }
     }
 
-    synchronized private SaslClient createSaslClient(final String 
servicePrincipal,
+    private SaslClient createSaslClient(final String servicePrincipal,
                                                      final String 
loginContext) throws LoginException {
         try {
             if (login == null) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("JAAS loginContext is: " + loginContext);
+                synchronized (ZooKeeperSaslClient.class) {
+                    if (login == null) {
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("JAAS loginContext is: " + loginContext);
+                        }
+                        // note that the login object is static: it's shared 
amongst all zookeeper-related connections.
+                        // in order to ensure the login is initialized only 
once, it must be synchronized the code snippet.
+                        login = new Login(loginContext, new 
ClientCallbackHandler(null));
+                        login.startThreadIfNeeded();
+                    }
                 }
-                // note that the login object is static: it's shared amongst 
all zookeeper-related connections.
-                // createSaslClient() must be declared synchronized so that 
login is initialized only once.
-                login = new Login(loginContext, new 
ClientCallbackHandler(null));
-                login.startThreadIfNeeded();
             }
             Subject subject = login.getSubject();
             SaslClient saslClient;


Reply via email to