This is an automated email from the ASF dual-hosted git repository.
liuxun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push:
new febe149 SUBMARINE-490. Synchronize user information from LDAP
febe149 is described below
commit febe149fd797ea68878a1e8511627a4a487e5755
Author: Eroschang <[email protected]>
AuthorDate: Wed May 13 02:15:35 2020 +0800
SUBMARINE-490. Synchronize user information from LDAP
### What is this PR for?
Test to synchronize user information from LDAP server.
### What type of PR is it?
Feature
### Todos
* [ ] - Task
### What is the Jira issue?
* Open an issue on Jira https://issues.apache.org/jira/browse/SUBMARINE/
* Put link here, and add [SUBMARINE-*Jira number*] in PR title, eg.
[SUBMARINE-23]
https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-490?filter=allopenissues&orderby=priority+ASC%2C+updated+DESC
### 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.
### Screenshots (if appropriate)
Edit the example.ldif file to add user in LDAP server.

Use testList() to test and get the user name which in LDAP server.

The user name in LDAP server.

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Eroschang <[email protected]>
Closes #286 from Eroschang/submarine-ldaptest and squashes the following
commits:
5d59787 [Eroschang] Add Logger to output log.
e5dac0c [Eroschang] Add embedded-ldap-junit.version number.
340446a [Eroschang] Make the version number to be variable.
d88b142 [Eroschang] Fix checkstyle.
c6ff2ed [Eroschang] Fix checkstyle.
2236cc7 [Eroschang] Change the package name and add apache license head.
0860bd6 [Eroschang] Add apache license head.
ccdd846 [Eroschang] Add LDAP user test.
---
pom.xml | 2 +
submarine-commons/commons-unixusersync/pom.xml | 96 ++++++++++++++
.../commons/unixusersync/EmbeddedLdapRuleTest.java | 142 +++++++++++++++++++++
.../src/test/resources/example.ldif | 70 ++++++++++
submarine-commons/pom.xml | 1 +
5 files changed, 311 insertions(+)
diff --git a/pom.xml b/pom.xml
index de427a3..d16b378 100644
--- a/pom.xml
+++ b/pom.xml
@@ -133,6 +133,8 @@
<jersey.test-framework>2.27</jersey.test-framework>
<!-- integration test-->
<plugin.failsafe.version>2.17</plugin.failsafe.version>
+ <!-- embedded-ldap-junit -->
+ <embedded-ldap-junit.version>0.7</embedded-ldap-junit.version>
</properties>
<modules>
diff --git a/submarine-commons/commons-unixusersync/pom.xml
b/submarine-commons/commons-unixusersync/pom.xml
new file mode 100644
index 0000000..a13d8b4
--- /dev/null
+++ b/submarine-commons/commons-unixusersync/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.submarine</groupId>
+ <artifactId>submarine-commons</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.submarine</groupId>
+ <artifactId>submarine-commons-unixusersync</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <name>Submarine: Commons Unixusersync</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>${commons-configuration.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.zapodot</groupId>
+ <artifactId>embedded-ldap-junit</artifactId>
+ <version>${embedded-ldap-junit.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
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
new file mode 100644
index 0000000..ede890f
--- /dev/null
+++
b/submarine-commons/commons-unixusersync/src/test/java/org/apache/submarine/commons/unixusersync/EmbeddedLdapRuleTest.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.submarine.commons.unixusersync;
+
+import com.google.common.collect.Iterators;
+
+import com.unboundid.ldap.sdk.AddRequest;
+import com.unboundid.ldap.sdk.Attribute;
+import com.unboundid.ldap.sdk.LDAPConnection;
+import com.unboundid.ldap.sdk.LDAPInterface;
+import com.unboundid.ldap.sdk.SearchRequest;
+import com.unboundid.ldap.sdk.SearchResult;
+import com.unboundid.ldap.sdk.SearchResultEntry;
+import com.unboundid.ldap.sdk.SearchScope;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.zapodot.junit.ldap.EmbeddedLdapRule;
+import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder;
+
+import javax.naming.Context;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class EmbeddedLdapRuleTest {
+
+ public static final String DOMAIN_DSN = "dc=zapodot,dc=org";
+ private static final Logger LOG =
LoggerFactory.getLogger(EmbeddedLdapRuleTest.class);
+
+ @Rule
+ public EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder
+ .newInstance()
+ .usingDomainDsn(DOMAIN_DSN)
+ .importingLdifs("example.ldif")
+ .build();
+
+ @Test
+ public void testLdapConnection() throws Exception {
+ final LDAPInterface ldapConnection = embeddedLdapRule.ldapConnection();
+ final SearchResult searchResult =
+ ldapConnection.search(DOMAIN_DSN, SearchScope.SUB,
"(objectClass=person)");
+
+ assertEquals(2, searchResult.getEntryCount());
+ }
+
+ @Test
+ public void testRawLdapConnection() throws Exception {
+ final String commonName = "Test person";
+ final String dn = String.format("cn=%s,ou=people,dc=zapodot,dc=org",
commonName);
+ LDAPConnection ldapConnection = embeddedLdapRule.unsharedLdapConnection();
+ try {
+ ldapConnection.add(new AddRequest(dn, Arrays.asList(
+ new Attribute("objectclass", "top",
+ "person", "organizationalPerson", "inetOrgPerson"),
+ new Attribute("cn", commonName), new Attribute("sn", "Person"),
+ new Attribute("uid", "test"))));
+ } finally {
+ // Forces the LDAP connection to be closed.
+ // This is not necessary as the rule will usually close it for you.
+ ldapConnection.close();
+ }
+ ldapConnection = embeddedLdapRule.unsharedLdapConnection();
+ final SearchResultEntry entry = ldapConnection.searchForEntry(new
SearchRequest(dn,
+ SearchScope.BASE,
+ "(objectClass=person)"));
+ assertNotNull(entry);
+ }
+
+ @Test
+ public void testDirContext() throws Exception {
+ final DirContext dirContext = embeddedLdapRule.dirContext();
+ final SearchControls searchControls = new SearchControls();
+ searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+ final NamingEnumeration<javax.naming.directory.SearchResult>
resultNamingEnumeration =
+ dirContext.search(DOMAIN_DSN, "(objectClass=person)",
searchControls);
+ assertEquals(2,
Iterators.size(Iterators.forEnumeration(resultNamingEnumeration)));
+ }
+
+ @Test
+ public void testContext() throws Exception {
+ final Context context = embeddedLdapRule.context();
+ final Object user = context.lookup("cn=Eros,ou=people,dc=zapodot,dc=org");
+ assertNotNull(user);
+ }
+
+ @Test
+ public void testList() throws Exception {
+ final Context context = embeddedLdapRule.context();
+ NamingEnumeration list = context.list("ou=semi-people,dc=zapodot,dc=org");
+
+ while (list.hasMore()){
+ NameClassPair nc = (NameClassPair) list.next();
+ System.out.println(nc.getName());
+ }
+
+ context.close();
+ }
+
+ @Test
+ public void testContextClose() throws Exception {
+ final Context context = embeddedLdapRule.context();
+ context.close();
+ assertNotNull(context.getNameInNamespace());
+ }
+
+ @Test
+ public void testEmbeddedServerPort() throws Exception {
+ assertTrue(embeddedLdapRule.embeddedServerPort() > 0);
+ }
+
+ private void assertTrue(boolean b) {
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNoPortAssignedYet() throws Exception {
+ final EmbeddedLdapRule embeddedLdapRule = new
EmbeddedLdapRuleBuilder().build();
+ embeddedLdapRule.embeddedServerPort();
+ }
+}
diff --git
a/submarine-commons/commons-unixusersync/src/test/resources/example.ldif
b/submarine-commons/commons-unixusersync/src/test/resources/example.ldif
new file mode 100644
index 0000000..818bd6c
--- /dev/null
+++ b/submarine-commons/commons-unixusersync/src/test/resources/example.ldif
@@ -0,0 +1,70 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+version: 1
+
+dn: dc=zapodot,dc=org
+objectClass: domain
+objectClass: top
+dc: zapodot
+
+dn: ou=groups,dc=zapodot,dc=org
+objectclass: top
+objectclass: organizationalUnit
+ou: groups
+
+dn: ou=people,dc=zapodot,dc=org
+objectclass: top
+objectclass: organizationalUnit
+ou: people
+
+dn: ou=semi-people,dc=zapodot,dc=org
+objectclass: top
+objectclass: organizationalUnit
+ou: people
+
+dn: ou=group-2,dc=zapodot,dc=org
+objectclass: top
+objectclass: organizationalUnit
+ou: people
+
+dn: cn=Eros,ou=people,dc=zapodot,dc=org
+objectclass: top
+objectclass: person
+objectclass: organizationalPerson
+objectclass: inetOrgPerson
+uid: zapodot
+userPassword: password
+cn: Sondre Eikanger Kvalo
+cn:: U29uZHJlIEVpa2FuZ2VyIEt2YWzDuA==
+sn: Person
+description: Developer
+ou: people
+
+dn: cn=Fake-Eros,ou=semi-people,dc=zapodot,dc=org
+objectclass: top
+objectclass: person
+objectclass: organizationalPerson
+objectclass: inetOrgPerson
+uid: zapodot
+userPassword: password
+cn: Sondre Eikanger Kvalo
+cn:: U29uZHJlIEVpa2FuZ2VyIEt2YWzDuA==
+sn: Person
+description: Developer
+ou: people
diff --git a/submarine-commons/pom.xml b/submarine-commons/pom.xml
index 00ba26b..da83d9f 100644
--- a/submarine-commons/pom.xml
+++ b/submarine-commons/pom.xml
@@ -40,6 +40,7 @@
<module>commons-cluster</module>
<module>commons-metastore</module>
<module>commons-rpc</module>
+ <module>commons-unixusersync</module>
</modules>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]