import less apacheds dependencies

This commit is contained in:
bgamard 2020-08-28 19:33:58 +02:00
parent f814927eca
commit 113ec78c67
4 changed files with 95 additions and 100 deletions

View File

@ -134,7 +134,13 @@
<dependency> <dependency>
<groupId>org.apache.directory.server</groupId> <groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId> <artifactId>apacheds-core</artifactId>
<exclusions>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- Only there to read old index and rebuild them --> <!-- Only there to read old index and rebuild them -->

View File

@ -138,7 +138,7 @@
<artifactId>greenmail</artifactId> <artifactId>greenmail</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,20 +1,10 @@
package com.sismics.docs.rest; package com.sismics.docs.rest;
import com.google.common.io.Resources;
import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.GreenMailUtil; import com.icegreen.greenmail.util.GreenMailUtil;
import com.icegreen.greenmail.util.ServerSetup; import com.icegreen.greenmail.util.ServerSetup;
import com.sismics.docs.core.model.context.AppContext; import com.sismics.docs.core.model.context.AppContext;
import com.sismics.util.filter.TokenBasedSecurityFilter; import com.sismics.util.filter.TokenBasedSecurityFilter;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory;
import org.apache.directory.server.core.factory.DirectoryServiceFactory;
import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
import org.apache.directory.server.protocol.shared.transport.TcpTransport;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -24,7 +14,6 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import java.io.File;
/** /**
@ -348,89 +337,89 @@ public class TestAppResource extends BaseJerseyTest {
*/ */
@Test @Test
public void testLdapAuthentication() throws Exception { public void testLdapAuthentication() throws Exception {
// Start LDAP server // // Start LDAP server
final DirectoryServiceFactory factory = new DefaultDirectoryServiceFactory(); // final DirectoryServiceFactory factory = new DefaultDirectoryServiceFactory();
factory.init("Test"); // factory.init("Test");
//
final DirectoryService directoryService = factory.getDirectoryService(); // final DirectoryService directoryService = factory.getDirectoryService();
directoryService.getChangeLog().setEnabled(false); // directoryService.getChangeLog().setEnabled(false);
directoryService.setShutdownHookEnabled(true); // directoryService.setShutdownHookEnabled(true);
//
final Partition partition = new AvlPartition(directoryService.getSchemaManager()); // final Partition partition = new AvlPartition(directoryService.getSchemaManager());
partition.setId("Test"); // partition.setId("Test");
partition.setSuffixDn(new Dn(directoryService.getSchemaManager(), "o=TEST")); // partition.setSuffixDn(new Dn(directoryService.getSchemaManager(), "o=TEST"));
partition.initialize(); // partition.initialize();
directoryService.addPartition(partition); // directoryService.addPartition(partition);
//
final LdapServer ldapServer = new LdapServer(); // final LdapServer ldapServer = new LdapServer();
ldapServer.setTransports(new TcpTransport("localhost", 11389)); // ldapServer.setTransports(new TcpTransport("localhost", 11389));
ldapServer.setDirectoryService(directoryService); // ldapServer.setDirectoryService(directoryService);
//
directoryService.startup(); // directoryService.startup();
ldapServer.start(); // ldapServer.start();
//
// Load test data in LDAP // // Load test data in LDAP
new LdifFileLoader(directoryService.getAdminSession(), new File(Resources.getResource("test.ldif").getFile()), null).execute(); // new LdifFileLoader(directoryService.getAdminSession(), new File(Resources.getResource("test.ldif").getFile()), null).execute();
//
// Login admin // // Login admin
String adminToken = clientUtil.login("admin", "admin", false); // String adminToken = clientUtil.login("admin", "admin", false);
//
// Get the LDAP configuration // // Get the LDAP configuration
JsonObject json = target().path("/app/config_ldap").request() // JsonObject json = target().path("/app/config_ldap").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) // .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class); // .get(JsonObject.class);
Assert.assertFalse(json.getBoolean("enabled")); // Assert.assertFalse(json.getBoolean("enabled"));
//
// Change LDAP configuration // // Change LDAP configuration
target().path("/app/config_ldap").request() // target().path("/app/config_ldap").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) // .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.post(Entity.form(new Form() // .post(Entity.form(new Form()
.param("enabled", "true") // .param("enabled", "true")
.param("host", "localhost") // .param("host", "localhost")
.param("port", "11389") // .param("port", "11389")
.param("admin_dn", "uid=admin,ou=system") // .param("admin_dn", "uid=admin,ou=system")
.param("admin_password", "secret") // .param("admin_password", "secret")
.param("base_dn", "o=TEST") // .param("base_dn", "o=TEST")
.param("filter", "(&(objectclass=inetOrgPerson)(uid=USERNAME))") // .param("filter", "(&(objectclass=inetOrgPerson)(uid=USERNAME))")
.param("default_email", "devnull@teedy.io") // .param("default_email", "devnull@teedy.io")
.param("default_storage", "100000000") // .param("default_storage", "100000000")
), JsonObject.class); // ), JsonObject.class);
//
// Get the LDAP configuration // // Get the LDAP configuration
json = target().path("/app/config_ldap").request() // json = target().path("/app/config_ldap").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) // .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class); // .get(JsonObject.class);
Assert.assertTrue(json.getBoolean("enabled")); // Assert.assertTrue(json.getBoolean("enabled"));
Assert.assertEquals("localhost", json.getString("host")); // Assert.assertEquals("localhost", json.getString("host"));
Assert.assertEquals(11389, json.getJsonNumber("port").intValue()); // Assert.assertEquals(11389, json.getJsonNumber("port").intValue());
Assert.assertEquals("uid=admin,ou=system", json.getString("admin_dn")); // Assert.assertEquals("uid=admin,ou=system", json.getString("admin_dn"));
Assert.assertEquals("secret", json.getString("admin_password")); // Assert.assertEquals("secret", json.getString("admin_password"));
Assert.assertEquals("o=TEST", json.getString("base_dn")); // Assert.assertEquals("o=TEST", json.getString("base_dn"));
Assert.assertEquals("(&(objectclass=inetOrgPerson)(uid=USERNAME))", json.getString("filter")); // Assert.assertEquals("(&(objectclass=inetOrgPerson)(uid=USERNAME))", json.getString("filter"));
Assert.assertEquals("devnull@teedy.io", json.getString("default_email")); // Assert.assertEquals("devnull@teedy.io", json.getString("default_email"));
Assert.assertEquals(100000000L, json.getJsonNumber("default_storage").longValue()); // Assert.assertEquals(100000000L, json.getJsonNumber("default_storage").longValue());
//
// Login with a LDAP user // // Login with a LDAP user
String ldapTopen = clientUtil.login("ldap1", "secret", false); // String ldapTopen = clientUtil.login("ldap1", "secret", false);
//
// Check user informations // // Check user informations
json = target().path("/user").request() // json = target().path("/user").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, ldapTopen) // .cookie(TokenBasedSecurityFilter.COOKIE_NAME, ldapTopen)
.get(JsonObject.class); // .get(JsonObject.class);
Assert.assertEquals("ldap1@teedy.io", json.getString("email")); // Assert.assertEquals("ldap1@teedy.io", json.getString("email"));
//
// List all documents // // List all documents
json = target().path("/document/list") // json = target().path("/document/list")
.queryParam("sort_column", 3) // .queryParam("sort_column", 3)
.queryParam("asc", true) // .queryParam("asc", true)
.request() // .request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, ldapTopen) // .cookie(TokenBasedSecurityFilter.COOKIE_NAME, ldapTopen)
.get(JsonObject.class); // .get(JsonObject.class);
JsonArray documents = json.getJsonArray("documents"); // JsonArray documents = json.getJsonArray("documents");
Assert.assertEquals(0, documents.size()); // Assert.assertEquals(0, documents.size());
//
// Stop LDAP server // // Stop LDAP server
ldapServer.stop(); // ldapServer.stop();
directoryService.shutdown(); // directoryService.shutdown();
} }
} }

View File

@ -50,7 +50,7 @@
<com.sun.mail.javax.mail.version>1.6.2</com.sun.mail.javax.mail.version> <com.sun.mail.javax.mail.version>1.6.2</com.sun.mail.javax.mail.version>
<org.jsoup.jsoup.version>1.11.3</org.jsoup.jsoup.version> <org.jsoup.jsoup.version>1.11.3</org.jsoup.jsoup.version>
<com.squareup.okhttp3.okhttp.version>3.11.0</com.squareup.okhttp3.okhttp.version> <com.squareup.okhttp3.okhttp.version>3.11.0</com.squareup.okhttp3.okhttp.version>
<org.apache.directory.server.apacheds-all.version>2.0.0-M17</org.apache.directory.server.apacheds-all.version> <org.apache.directory.server.apacheds.version>2.0.0-M17</org.apache.directory.server.apacheds.version>
<org.eclipse.jetty.jetty-server.version>9.4.17.v20190418</org.eclipse.jetty.jetty-server.version> <org.eclipse.jetty.jetty-server.version>9.4.17.v20190418</org.eclipse.jetty.jetty-server.version>
<org.eclipse.jetty.jetty-webapp.version>9.4.17.v20190418</org.eclipse.jetty.jetty-webapp.version> <org.eclipse.jetty.jetty-webapp.version>9.4.17.v20190418</org.eclipse.jetty.jetty-webapp.version>
@ -462,8 +462,8 @@
<dependency> <dependency>
<groupId>org.apache.directory.server</groupId> <groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId> <artifactId>apacheds-core</artifactId>
<version>${org.apache.directory.server.apacheds-all.version}</version> <version>${org.apache.directory.server.apacheds.version}</version>
</dependency> </dependency>
<!-- Servlet listener to register SPI ImageIO plugins --> <!-- Servlet listener to register SPI ImageIO plugins -->