From b85d4099bf0634f99691fd5d80a5e9408561f678 Mon Sep 17 00:00:00 2001 From: Eroschang Date: Fri, 3 Jul 2020 14:41:03 +0800 Subject: [PATCH] SUBMARINE-551. Add a test of user identity verification ### What is this PR for? To test the LDAP for user verification. The user in this open LDAP server can be verified successfully. ### What type of PR is it? Improvement ### Todos * [ ] - Task ### What is the Jira issue? https://issues.apache.org/jira/browse/SUBMARINE-551 ### How should this be tested? * First time? Setup Travis CI as described on https://submarine.apache.org/contribution/contributions.html#continuous-integration * Strongly recommended: add automated unit tests for any new or changed behavior * Outline any manual steps to test the PR here. https://travis-ci.org/github/Eroschang/submarine/builds/703852786 ### Screenshots (if appropriate) ![image](https://user-images.githubusercontent.com/43379142/86231254-d92fe400-bbc4-11ea-8000-ed12af7a2f3e.png) ### Questions: * Does the licenses files need update? /No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Eroschang Closes #337 from Eroschang/SUBMARINE-551 and squashes the following commits: ff78c95 [Eroschang] Add a test of user identity verification. cbb9d28 [Eroschang] Add a test of user identity verification. 0fca95a [Eroschang] Add a test of user identity verification. --- .../unixusersync/EmbeddedLdapRuleTest.java | 33 +++++++++++++++++++ 1 file changed, 33 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..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();