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..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 @@ -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,36 @@ 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); + LOG.info("Pass"); + } + catch (AuthenticationException e) { + LOG.error(e.getMessage(), e); + } + catch (javax.naming.CommunicationException e) { + LOG.error(e.getMessage(), e); + } + catch (Exception e) { + LOG.error(e.getMessage(), e); + } + } + @Test public void testContextClose() throws Exception { final Context context = embeddedLdapRule.context();