Permalink
Browse files

ZOOKEEPER-1550. ZooKeeperSaslClient does not finish anonymous login o…

…n OpenJDK (Eugene Koontz via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1391526 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 7c7856f commit ba41effebc8f52c89672bbb8e861b277fdb99bf4 Mahadev Konar committed Sep 28, 2012
View
@@ -255,6 +255,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-1170. Fix compiler (eclipse) warnings: unused imports,
@@ -270,6 +270,10 @@ public Subject getSubject() {
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. " +
@@ -23,6 +23,7 @@
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 @@
Environment.logEnv("Client environment:", LOG);
}
+ public ZooKeeperSaslClient getSaslClient() {
+ return cnxn.zooKeeperSaslClient;
+ }
+
private final ZKWatchManager watchManager = new ZKWatchManager();
List<String> getDataWatches() {
@@ -76,10 +76,10 @@ public SaslState getSaslState() {
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 @@ synchronized private SaslClient createSaslClient(final String servicePrincipal,
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 boolean clientTunneledAuthenticationInProgress() {
// 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) &&
@@ -21,13 +21,10 @@
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 @@ to use it (we're configured by the above System.setProperty(...LOGIN_CONTEXT_NA
}
}
- 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 void testAuth() throws Exception {
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();
+ }
+ }
+
+
}

0 comments on commit ba41eff

Please sign in to comment.