Author: rakeshr Date: Wed Mar 2 06:46:43 2016 New Revision: 1733221 URL: http://svn.apache.org/viewvc?rev=1733221&view=rev Log: ZOOKEEPER-2375: Prevent multiple initialization of login object in each ZooKeeperSaslClient instance (yuemeng via rakeshr)
Modified: zookeeper/trunk/CHANGES.txt zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java Modified: zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1733221&r1=1733220&r2=1733221&view=diff ============================================================================== --- zookeeper/trunk/CHANGES.txt (original) +++ zookeeper/trunk/CHANGES.txt Wed Mar 2 06:46:43 2016 @@ -254,6 +254,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-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex) Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java?rev=1733221&r1=1733220&r2=1733221&view=diff ============================================================================== --- zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java (original) +++ zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java Wed Mar 2 06:46:43 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;