From 0fca95a6813d5e4c4d7ffdf5e62c3ee62537097f Mon Sep 17 00:00:00 2001 From: Eroschang Date: Wed, 1 Jul 2020 17:55:33 +0800 Subject: [PATCH 1/3] Add a test of user identity verification. --- .../unixusersync/EmbeddedLdapRuleTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java b/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java index 7727a8d953..d97328c85f 100644 --- a/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java +++ b/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java @@ -35,13 +35,16 @@ import org.zapodot.junit.ldap.EmbeddedLdapRule; import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; +import javax.naming.AuthenticationException; import javax.naming.Context; import javax.naming.NameClassPair; import javax.naming.NamingEnumeration; import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; import javax.naming.directory.SearchControls; import java.util.ArrayList; import java.util.Arrays; +import java.util.Hashtable; import java.util.StringTokenizer; import static org.junit.Assert.assertEquals; @@ -133,6 +136,39 @@ public void testList() throws Exception { context.close(); } + @Test + public void testauth() throws Exception { + DirContext ctx = null; + Hashtable HashEnv = new Hashtable(); + + String loginId = "uid=curie,dc=example,dc=com"; + String password = "password"; + + HashEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); + HashEnv.put(Context.SECURITY_PRINCIPAL, loginId); + HashEnv.put(Context.SECURITY_CREDENTIALS, password); + HashEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); + HashEnv.put("com.sun.jndi.ldap.connect.timeout", "3000"); + HashEnv.put(Context.PROVIDER_URL, "ldap://ldap.forumsys.com:389"); + + try { + ctx = new InitialDirContext(HashEnv); + System.out.println("Pass"); + } + catch (AuthenticationException e) { + System.out.println("fail"); + e.printStackTrace(); + } + catch (javax.naming.CommunicationException e) { + System.out.println("Connection fail"); + e.printStackTrace(); + } + catch (Exception e) { + System.out.println("Unknown identity verification fail"); + e.printStackTrace(); + } + } + @Test public void testContextClose() throws Exception { final Context context = embeddedLdapRule.context(); From cbb9d282e776d1726aebdba7b1e80c6238ebdc0c Mon Sep 17 00:00:00 2001 From: Eroschang Date: Thu, 2 Jul 2020 02:20:18 +0800 Subject: [PATCH 2/3] Add a test of user identity verification. --- .../unixusersync/EmbeddedLdapRuleTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java b/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java index d97328c85f..4aa283aa9a 100644 --- a/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java +++ b/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java @@ -137,7 +137,7 @@ public void testList() throws Exception { } @Test - public void testauth() throws Exception { + public void testauth() throws Exception { DirContext ctx = null; Hashtable HashEnv = new Hashtable(); @@ -153,19 +153,19 @@ public void testauth() throws Exception { try { ctx = new InitialDirContext(HashEnv); - System.out.println("Pass"); + LOG.info("Pass"); } catch (AuthenticationException e) { - System.out.println("fail"); - e.printStackTrace(); + LOG.info("fail"); + LOG.error(e.getMessage(), e); } catch (javax.naming.CommunicationException e) { - System.out.println("Connection fail"); - e.printStackTrace(); + LOG.info("Connection fail"); + LOG.error(e.getMessage(), e); } catch (Exception e) { - System.out.println("Unknown identity verification fail"); - e.printStackTrace(); + LOG.info("Unknown identity verification fail"); + LOG.error(e.getMessage(), e); } } From ff78c95d45e097df07267c977b4748074cffb11c Mon Sep 17 00:00:00 2001 From: Eroschang Date: Fri, 3 Jul 2020 14:41:03 +0800 Subject: [PATCH 3/3] Add a test of user identity verification. --- .../submarine/commons/unixusersync/EmbeddedLdapRuleTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java b/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java index 4aa283aa9a..42f2ce99a9 100644 --- a/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java +++ b/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java @@ -156,15 +156,12 @@ public void testauth() throws Exception { LOG.info("Pass"); } catch (AuthenticationException e) { - LOG.info("fail"); LOG.error(e.getMessage(), e); } catch (javax.naming.CommunicationException e) { - LOG.info("Connection fail"); LOG.error(e.getMessage(), e); } catch (Exception e) { - LOG.info("Unknown identity verification fail"); LOG.error(e.getMessage(), e); } }