zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1391555 - in /zookeeper/branches/branch-3.4: ./ src/java/main/org/apache/zookeeper/ src/java/main/org/apache/zookeeper/client/ src/java/test/org/apache/zookeeper/test/
Date Fri, 28 Sep 2012 17:03:55 GMT
Author: mahadev
Date: Fri Sep 28 17:03:55 2012
New Revision: 1391555

URL: http://svn.apache.org/viewvc?rev=1391555&view=rev
Log:
ZOOKEEPER-1550. ZooKeeperSaslClient does not finish anonymous login on OpenJDK. (Eugene Koontz
via mahadev)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Login.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1391555&r1=1391554&r2=1391555&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Fri Sep 28 17:03:55 2012
@@ -123,6 +123,9 @@ BUGFIXES:
   ZOOKEEPER-1496. Ephemeral node not getting cleared even after client has
   exited (Rakesh R via mahadev)
 
+  ZOOKEEPER-1550. ZooKeeperSaslClient does not finish anonymous login on
+  OpenJDK. (Eugene Koontz via mahadev)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1389. it would be nice if start-foreground used exec $JAVA

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Login.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Login.java?rev=1391555&r1=1391554&r2=1391555&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Login.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/Login.java Fri Sep 28
17:03:55 2012
@@ -276,6 +276,10 @@ public class Login {
         return subject;
     }
 
+    public String getLoginContextName() {
+        return loginContextName;
+    }
+
     private synchronized LoginContext login(final String loginContextName) throws LoginException
{
         if (loginContextName == null) {
             throw new LoginException("loginContext name (JAAS file section header) was null.
" +

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java?rev=1391555&r1=1391554&r2=1391555&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/ZooKeeper.java Fri Sep
28 17:03:55 2012
@@ -23,6 +23,7 @@ import org.apache.zookeeper.OpResult.Err
 import org.apache.zookeeper.client.ConnectStringParser;
 import org.apache.zookeeper.client.HostProvider;
 import org.apache.zookeeper.client.StaticHostProvider;
+import org.apache.zookeeper.client.ZooKeeperSaslClient;
 import org.apache.zookeeper.common.PathUtils;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
@@ -94,6 +95,10 @@ public class ZooKeeper {
         Environment.logEnv("Client environment:", LOG);
     }
 
+    public ZooKeeperSaslClient getSaslClient() {
+        return cnxn.zooKeeperSaslClient;
+    }
+
     private final ZKWatchManager watchManager = new ZKWatchManager();
 
     List<String> getDataWatches() {

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java?rev=1391555&r1=1391554&r2=1391555&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
Fri Sep 28 17:03:55 2012
@@ -76,10 +76,10 @@ public class ZooKeeperSaslClient {
         return saslState;
     }
 
-    private String loginContext;
-
     public String getLoginContext() {
-      return loginContext;
+        if (login != null)
+            return login.getLoginContextName();
+        return null;
     }
 
     public ZooKeeperSaslClient(final String serverPrincipal)
@@ -193,7 +193,6 @@ public class ZooKeeperSaslClient {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("JAAS loginContext is: " + loginContext);
                 }
-                this.loginContext = loginContext;
                 // 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));
@@ -485,9 +484,14 @@ public class ZooKeeperSaslClient {
         // variable or method in this class to determine whether the client is
         // configured to use SASL. (see also ZOOKEEPER-1455).
         try {
-            if ((System.getProperty(Environment.JAAS_CONF_KEY) != null) ||
-                (javax.security.auth.login.Configuration.getConfiguration() != null)) {
-                // Client is configured to use SASL.
+  	    if ((System.getProperty(Environment.JAAS_CONF_KEY) != null) ||
+              ((javax.security.auth.login.Configuration.getConfiguration() != null) &&
+                  (javax.security.auth.login.Configuration.getConfiguration().
+                       getAppConfigurationEntry(System.
+                       getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY,"Client"))

+                           != null))) {
+                // Client is configured to use a valid login Configuration, so
+                // authentication is either in progress, successful, or failed.
 
                 // 1. Authentication hasn't finished yet: we must wait for it to do so.
                 if ((isComplete() == false) &&

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java?rev=1391555&r1=1391554&r2=1391555&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java
Fri Sep 28 17:03:55 2012
@@ -21,13 +21,10 @@ package org.apache.zookeeper.test;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.client.ZooKeeperSaslClient;
 import org.junit.Assert;
@@ -68,20 +65,6 @@ public class SaslAuthDesignatedClientTes
         }
     }
 
-    private AtomicInteger authFailed = new AtomicInteger(0);
-
-    private class MyWatcher extends CountdownWatcher {
-        @Override
-        public synchronized void process(WatchedEvent event) {
-            if (event.getState() == KeeperState.AuthFailed) {
-                authFailed.incrementAndGet();
-            }
-            else {
-                super.process(event);
-            }
-        }
-    }
-
     @Test
     public void testAuth() throws Exception {
         ZooKeeper zk = createClient();
@@ -95,4 +78,27 @@ public class SaslAuthDesignatedClientTes
             zk.close();
         }
     }
+
+    @Test
+    public void testSaslConfig() throws Exception {
+        ZooKeeper zk = createClient();
+        try {
+            zk.getChildren("/", false);
+            Assert.assertFalse(zk.getSaslClient().
+                clientTunneledAuthenticationInProgress());
+            Assert.assertEquals(zk.getSaslClient().getSaslState(),
+                ZooKeeperSaslClient.SaslState.COMPLETE);
+            Assert.assertNotNull(
+                javax.security.auth.login.Configuration.getConfiguration().
+                    getAppConfigurationEntry("MyZookeeperClient"));
+            Assert.assertSame(zk.getSaslClient().getLoginContext(),
+                "MyZookeeperClient");
+        } catch (KeeperException e) {
+            Assert.fail("test failed :" + e);
+        } finally {
+            zk.close();
+        }
+    }
+
+
 }



Mime
View raw message