james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [james-project] 02/24: JAMES-2720 Perform LDAP configuration manually
Date Thu, 11 Apr 2019 00:33:33 GMT
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit b78cddeb8cdd17f44b195b79e28d3931f1e4dc44
Author: Benoit Tellier <btellier@linagora.com>
AuthorDate: Wed Apr 10 10:00:20 2019 +0700

    JAMES-2720 Perform LDAP configuration manually
---
 .../james/linshare/LDAPConfigurationPerformer.java | 122 +++++++++++++++++++++
 .../java/org/apache/james/linshare/Linshare.java   |  34 +-----
 .../linshare/src/test/resources/docker-compose.yml |  21 +---
 third-party/linshare/src/test/resources/ssl/id_rsa |  27 +++++
 .../linshare/src/test/resources/ssl/id_rsa.pub     |   1 +
 5 files changed, 157 insertions(+), 48 deletions(-)

diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LDAPConfigurationPerformer.java
b/third-party/linshare/src/test/java/org/apache/james/linshare/LDAPConfigurationPerformer.java
new file mode 100644
index 0000000..d74d445
--- /dev/null
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/LDAPConfigurationPerformer.java
@@ -0,0 +1,122 @@
+/****************************************************************
+ * 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.james.linshare;
+
+import static io.restassured.RestAssured.given;
+import static io.restassured.config.EncoderConfig.encoderConfig;
+import static io.restassured.config.RestAssuredConfig.newConfig;
+
+import java.nio.charset.StandardCharsets;
+
+import io.restassured.authentication.BasicAuthScheme;
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+
+class LDAPConfigurationPerformer {
+    static void configureLdap(Linshare linshare) {
+        BasicAuthScheme basicAuthScheme = new BasicAuthScheme();
+        basicAuthScheme.setUserName("root@localhost.localdomain");
+        basicAuthScheme.setPassword("adminlinshare");
+
+        RequestSpecification specification = new RequestSpecBuilder()
+            .setContentType(ContentType.JSON)
+            .setAccept(ContentType.JSON)
+            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
+            .setBaseUri("http://" + linshare.getIp())
+            .setPort(linshare.getPort())
+            .setAuth(basicAuthScheme)
+            .build();
+
+        String ldapId = given(specification)
+            .body("{" +
+                "  \"label\":\"ldap-local\"," +
+                "  \"providerUrl\":\"ldap://ldap:389\"," +
+                "  \"securityPrincipal\":\"cn=linshare,dc=linshare,dc=org\"," +
+                "  \"securityCredentials\":\"linshare\"" +
+                "}")
+            .post("/linshare/webservice/rest/admin/ldap_connections")
+            .jsonPath()
+            .getString("uuid");
+
+        given(specification)
+            .body("{" +
+                "  \"uuid\":\"868400c0-c12e-456a-8c3c-19e985290586\"," +
+                "  \"label\":\"openldap-local\"," +
+                "  \"description\":\"This is pattern the default pattern for the OpenLdap
structure.\"," +
+                "  \"authCommand\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=*)(givenName=*)(sn=*)(|(mail=\\\"+login+\\\")(uid=\\\"+login+\\\")))\\\");\","
+
+                "  \"searchUserCommand\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=\\\"+mail+\\\")(givenName=\\\"+first_name+\\\")(sn=\\\"+last_name+\\\"))\\\");\","
+
+                "  \"userMail\":\"mail\"," +
+                "  \"userFirstName\":\"givenName\"," +
+                "  \"userLastName\":\"sn\"," +
+                "  \"ldapUid\":\"uid\"," +
+                "  \"autoCompleteCommandOnAllAttributes\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=*)(givenName=*)(sn=*)(|(mail=\\\"
+ pattern + \\\")(sn=\\\" + pattern + \\\")(givenName=\\\" + pattern + \\\")))\\\");\"," +
+                "  \"autoCompleteCommandOnFirstAndLastName\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=*)(givenName=*)(sn=*)(|(&(sn=\\\"
+ first_name + \\\")(givenName=\\\" + last_name + \\\"))(&(sn=\\\" + last_name + \\\")(givenName=\\\"
+ first_name + \\\"))))\\\");\"," +
+                "  \"searchPageSize\":100," +
+                "  \"searchSizeLimit\":100," +
+                "  \"completionPageSize\":10," +
+                "  \"completionSizeLimit\":10" +
+                "}")
+            .post("/linshare/webservice/rest/admin/domain_patterns");
+
+        String ldapPatternId = given(specification)
+            .get("/linshare/webservice/rest/admin/domain_patterns")
+            .getBody()
+            .jsonPath()
+            .getString("[0].uuid");
+
+        String mimePolicyId = given(specification)
+            .get("/linshare/webservice/rest/admin/mime_policies?domainId=LinShareRootDomain&onlyCurrentDomain=false")
+            .jsonPath()
+            .getString("[0].uuid");
+
+        String welcomeMessageId = given(specification)
+            .get("/linshare/webservice/rest/admin/welcome_messages?domainId=LinShareRootDomain&parent=true")
+            .jsonPath()
+            .getString("[0].uuid");
+
+        String mailConfigId = given(specification)
+            .get("/linshare/webservice/rest/admin/mail_configs?domainId=LinShareRootDomain&onlyCurrentDomain=false")
+            .jsonPath()
+            .getString("[0].uuid");
+
+        given(specification)
+            .body("{" +
+                "  \"parent\":\"LinShareRootDomain\"," +
+                "  \"type\":\"TOPDOMAIN\"," +
+                "  \"providers\":[" +
+                "    {" +
+                "      \"ldapConnectionUuid\":\"" + ldapId + "\"," +
+                "      \"userLdapPatternUuid\":\"" + ldapPatternId + "\"," +
+                "      \"baseDn\":\"ou=People,dc=linshare,dc=org\"" +
+                "     }]," +
+                "  \"externalMailLocale\":\"ENGLISH\"," +
+                "  \"language\":\"ENGLISH\"," +
+                "  \"mailConfigUuid\":\"" + mailConfigId + "\"," +
+                "  \"currentWelcomeMessage\":{\"uuid\":\"" + welcomeMessageId + "\"}," +
+                "  \"mimePolicyUuid\":\"" + mimePolicyId + "\"," +
+                "  \"userRole\":\"SIMPLE\"," +
+                "  \"policy\":{\"identifier\":\"DefaultDomainPolicy\"}," +
+                "  \"label\":\"linshare.org\"," +
+                "  \"description\":\"linshare.org domain\"" +
+                "}")
+            .post("/linshare/webservice/rest/admin/domains");
+    }
+}
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java b/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
index 7f90649..348ed17 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.linshare;
 
+import java.time.Duration;
+
 import org.testcontainers.containers.BindMode;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.Network;
@@ -31,7 +33,6 @@ public class Linshare {
 
     private final GenericContainer<?> linshareBackend;
     private final GenericContainer<?> linshareDatabase;
-    private final GenericContainer<?> linshareDatabaseInit;
     private final GenericContainer<?> linshareSmtp;
     private final GenericContainer<?> linshareLdap;
     private final GenericContainer<?> linshareMongodb;
@@ -46,7 +47,6 @@ public class Linshare {
         linshareLdap = createDockerLdap();
         linshareSmtp = createDockerSmtp();
         linshareBackend = createDockerBackend();
-        linshareDatabaseInit = createDockerDatabaseInit();
     }
 
     public void start() {
@@ -55,7 +55,8 @@ public class Linshare {
         linshareLdap.start();
         linshareSmtp.start();
         linshareBackend.start();
-        linshareDatabaseInit.start();
+
+        LDAPConfigurationPerformer.configureLdap(this);
     }
 
     public void stop() {
@@ -64,7 +65,6 @@ public class Linshare {
         linshareLdap.stop();
         linshareSmtp.stop();
         linshareBackend.stop();
-        linshareDatabaseInit.stop();
     }
 
     public int getPort() {
@@ -106,23 +106,6 @@ public class Linshare {
             .withNetwork(network);
     }
 
-    private GenericContainer createDockerDatabaseInit() {
-        return new GenericContainer<>("chibenwa/linshare-database-init:2.2")
-            .withEnv("TOMCAT_HOST", "backend")
-            .withEnv("TOMCAT_PORT", "8080")
-            .withEnv("TOMCAT_LDAP_NAME", "ldap-local")
-            .withEnv("TOMCAT_LDAP_URL", "ldap://ldap:389")
-            .withEnv("TOMCAT_LDAP_BASE_DN", "ou=People,dc=linshare,dc=org")
-            .withEnv("TOMCAT_LDAP_DN", "cn=linshare,dc=linshare,dc=org")
-            .withEnv("TOMCAT_LDAP_PW", "linshare")
-            .withEnv("TOMCAT_DOMAIN_PATTERN_NAME", "openldap-local")
-            .withEnv("TOMCAT_DOMAIN_PATTERN_MODEL", "868400c0-c12e-456a-8c3c-19e985290586")
-            .withEnv("NO_REPLY_ADDRESS", "linshare-noreply@linshare.org")
-            .withEnv("DEBUG", "1")
-            .withNetwork(network)
-            .waitingFor(Wait.forLogMessage(WAIT_FOR_DB_INIT_LOG, 1));
-    }
-
     private GenericContainer createDockerBackend() {
         return new GenericContainer<>("linagora/linshare-backend:2.2")
             .withNetworkAliases("backend")
@@ -141,14 +124,9 @@ public class Linshare {
             .withClasspathResourceMapping("./conf/log4j.properties",
                 "/etc/linshare/log4j.properties",
                 BindMode.READ_ONLY)
-            .withClasspathResourceMapping("./ssl/id_rsa",
-                "/etc/linshare/id_rsa",
-                BindMode.READ_ONLY)
-            .withClasspathResourceMapping("./ssl/id_rsa.pub",
-                "/etc/linshare/id_rsa.pub",
-                BindMode.READ_ONLY)
             .withExposedPorts(LINSHARE_BACKEND_PORT)
-            .waitingFor(Wait.forLogMessage(WAIT_FOR_BACKEND_INIT_LOG, 1))
+            .waitingFor(Wait.forLogMessage(WAIT_FOR_BACKEND_INIT_LOG, 1)
+                .withStartupTimeout(Duration.ofMinutes(10)))
             .withNetwork(network);
     }
 }
diff --git a/third-party/linshare/src/test/resources/docker-compose.yml b/third-party/linshare/src/test/resources/docker-compose.yml
index e869bea..f0508a4 100644
--- a/third-party/linshare/src/test/resources/docker-compose.yml
+++ b/third-party/linshare/src/test/resources/docker-compose.yml
@@ -55,23 +55,4 @@ services:
     ldap:
         image: linagora/linshare-ldap-for-tests:1.0
         tty: true
-        stdin_open: true
-
-    database-init:
-        image: chibenwa/linshare-database-init:2.2
-        links:
-            - backend:backend
-        depends_on:
-            - backend
-        environment:
-            - TOMCAT_HOST=backend
-            - TOMCAT_PORT=8080
-            - TOMCAT_LDAP_NAME=ldap-local
-            - TOMCAT_LDAP_URL=ldap://ldap:389
-            - TOMCAT_LDAP_BASE_DN=ou=People,dc=linshare,dc=org
-            - TOMCAT_LDAP_DN=cn=linshare,dc=linshare,dc=org
-            - TOMCAT_LDAP_PW=linshare
-            - TOMCAT_DOMAIN_PATTERN_NAME=openldap-local
-            - TOMCAT_DOMAIN_PATTERN_MODEL=868400c0-c12e-456a-8c3c-19e985290586
-            - NO_REPLY_ADDRESS=linshare-noreply@linshare.org
-            - DEBUG=1
\ No newline at end of file
+        stdin_open: true
\ No newline at end of file
diff --git a/third-party/linshare/src/test/resources/ssl/id_rsa b/third-party/linshare/src/test/resources/ssl/id_rsa
new file mode 100644
index 0000000..b829322
--- /dev/null
+++ b/third-party/linshare/src/test/resources/ssl/id_rsa
@@ -0,0 +1,27 @@
+-----BEGIN OPENSSH PRIVATE KEY-----
+b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
+NhAAAAAwEAAQAAAQEA4B+4pS43XYFbCG8w8sEGao0uPFulLyqBRZbzq4RXc6lL4KV4OnQX
+9zx/fL34O/qQEvmwvHmbXY3uv4jxlvC9uolQqEPx96b3sOUYc30L1yejQODW4dZCdZjj7+
+n8+oALez4eYkb/A7Qqo3CPy/YgF+T0KS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Rr5krvo85TFDyh87HUdgnzvjqMw8BXPRF9ZvaMLuu52vwrv1GHg
+4Imqs4DJL4AAAAgQD4dRSORzIxhRN1RHvEkuRZiGfPF8n4Xrjmz6bCnGvuqnA0yHQ6oecr
+CTTAQdAyDRgP4yNXCyyDZVkQpcIHwVvV+oyNxCFdkOm05TrgycHgKerGNUb4VEv23L0BAX
+lDqLLLtSYxl1ZQFoThSlzd3N4JSw48koNnbq67j+HiHgTr8wAAAIEA5u2HyYSs6evLVJNP
+3DKUyNymujQ3v+E7rUnlz/cGaEuVAh/wZm7rYmcljcyUFDMtKmpW65SB4i6VEEWAVcnROk
+U2kJaUvTSb6S7a7BjtweBDqplSh16DVuPpTKp24CKJhSVMi1bwoaMzlAUq5ve1JXw7zHF7
+Y9BHujDJ1SfN2akAAAANYmVud2FAaG9yaXpvbgECAwQFBg==
+-----END OPENSSH PRIVATE KEY-----
diff --git a/third-party/linshare/src/test/resources/ssl/id_rsa.pub b/third-party/linshare/src/test/resources/ssl/id_rsa.pub
new file mode 100644
index 0000000..d1666e1
--- /dev/null
+++ b/third-party/linshare/src/test/resources/ssl/id_rsa.pub
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDgH7ilLjddgVsIbzDywQZqjS48W6UvKoFFlvOrhFdzqUvgpXg6dBf3PH98vfg7+pAS+bC8eZtdje6/iPGW8L26iVCoQ/H3pvew5RhzfQvXJ6NA4Nbh1kJ1mOPv6fz6gAt7Ph5iRv8DtCqjcI/L9iAX5PQpKlwKjdTvabFJiVEEUtsZcX+FbI0uJe/ixrwgS+7UzL3LdYYnw4u9yU7+xK+9w9sx96ugf557OJzRdAZRRxiOzV0Vlei/fDAk/UnCDtFf9142Ci8NmGb6pdxWNPWl+aJvnpSr9n7ntk7IfQWHYDzu6tRhPRBVU8dOp2a0Y5LdlkksquvbbMADr8nz175r
benwa@horizon


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message