Repository: tinkerpop Updated Branches: refs/heads/master 0c2fc21fb -> c8e4fec98
Another attempt to wait for flushed logs on kerberos tests CTR Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b9ebe159 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b9ebe159 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b9ebe159 Branch: refs/heads/master Commit: b9ebe15990b44bde0e2592ba62d52343d73edb4e Parents: b12a3fd Author: Stephen Mallette <sp...@genoprime.com> Authored: Fri Aug 10 08:04:20 2018 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Fri Aug 10 08:04:20 2018 -0400 ---------------------------------------------------------------------- .../gremlin/server/auth/Krb5Authenticator.java | 10 ++-- .../GremlinServerAuthKrb5IntegrateTest.java | 49 ++++++++++---------- 2 files changed, 27 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b9ebe159/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/Krb5Authenticator.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/Krb5Authenticator.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/Krb5Authenticator.java index a92e404..f4e5d77 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/Krb5Authenticator.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/Krb5Authenticator.java @@ -66,6 +66,7 @@ public class Krb5Authenticator implements Authenticator { "Could not configure a %s - provide a 'config' in the 'authentication' settings", Krb5Authenticator.class.getName())); } + try { final File keytabFile = new File((String) config.get(KEYTAB_KEY)); principalName = (String) config.get(PRINCIPAL_KEY); @@ -73,19 +74,14 @@ public class Krb5Authenticator implements Authenticator { } catch (Exception e) { logger.warn("Failed to login to kdc"); } + logger.debug("Done logging in to kdc"); } @Override public SaslNegotiator newSaslNegotiator(final InetAddress remoteAddress) { logger.debug("newSaslNegotiator() called"); - return Subject.doAs(subject, - new PrivilegedAction<SaslNegotiator>() { - public SaslNegotiator run() { - return new Krb5SaslAuthenticator(); - } - } - ); + return Subject.doAs(subject, (PrivilegedAction<SaslNegotiator>) Krb5SaslAuthenticator::new); } public AuthenticatedUser authenticate(final Map<String, String> credentials) throws AuthenticationException { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b9ebe159/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java index 10ed834..c102446 100644 --- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthKrb5IntegrateTest.java @@ -39,15 +39,14 @@ import java.util.HashMap; import java.util.Map; import javax.security.auth.login.LoginException; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - - /** * @author Marc de Lignie - * */ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerIntegrationTest { private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GremlinServerAuthKrb5IntegrateTest.class); @@ -180,32 +179,17 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt @Test public void shouldFailWithNonexistentServerPrincipal() throws Exception { - - // wait for logger to flush - (don't think there is a way to detect this) - stopServer(); - Thread.sleep(1000); - - assertTrue(recordingAppender.logContainsAny("WARN - Failed to login to kdc")); + assertFailedLogin(); } @Test public void shouldFailWithEmptyServerKeytab() throws Exception { - - // wait for logger to flush - (don't think there is a way to detect this) - stopServer(); - Thread.sleep(1000); - - assertTrue(recordingAppender.logContainsAny("WARN - Failed to login to kdc")); + assertFailedLogin(); } @Test public void shouldFailWithWrongServerKeytab() throws Exception { - - // wait for logger to flush - (don't think there is a way to detect this) - stopServer(); - Thread.sleep(1000); - - assertTrue(recordingAppender.logContainsAny("WARN - Failed to login to kdc")); + assertFailedLogin(); } @Test @@ -241,8 +225,8 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt @Test public void shouldAuthenticateWithSerializeResultToStringV1() throws Exception { - MessageSerializer serializer = new GryoMessageSerializerV1d0(); - Map config = new HashMap<String, Object>(); + final MessageSerializer serializer = new GryoMessageSerializerV1d0(); + final Map<String,Object> config = new HashMap<>(); config.put("serializeResultToString", true); serializer.configure(config, null); final Cluster cluster = TestClientFactory.build().jaasEntry(TESTCONSOLE) @@ -259,8 +243,8 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt @Test public void shouldAuthenticateWithSerializeResultToStringV3() throws Exception { - MessageSerializer serializer = new GryoMessageSerializerV3d0(); - Map config = new HashMap<String, Object>(); + final MessageSerializer serializer = new GryoMessageSerializerV3d0(); + final Map<String, Object> config = new HashMap<>(); config.put("serializeResultToString", true); serializer.configure(config, null); final Cluster cluster = TestClientFactory.build().jaasEntry(TESTCONSOLE) @@ -274,4 +258,19 @@ public class GremlinServerAuthKrb5IntegrateTest extends AbstractGremlinServerInt cluster.close(); } } + + /** + * Tries to force the logger to flush fully or at least wait until it does. + */ + private void assertFailedLogin() throws Exception { + stopServer(); + + boolean logMessageIdentified = false; + for (int ix = 0; ix < 10 && !logMessageIdentified; ix++) { + logMessageIdentified = recordingAppender.logContainsAny("WARN - Failed to login to kdc"); + if (!logMessageIdentified) Thread.sleep(1000); + } + + assertThat(logMessageIdentified, is(true)); + } }