Skip to content

Commit

Permalink
Fix for LDAP testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandor777 committed May 8, 2019
1 parent eca5d44 commit c95b86a
Show file tree
Hide file tree
Showing 16 changed files with 536 additions and 593 deletions.
5 changes: 3 additions & 2 deletions src/pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -866,8 +866,9 @@
<dependency> <dependency>
<groupId>org.springframework.ldap</groupId> <groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-test</artifactId> <artifactId>spring-ldap-test</artifactId>
<version>1.3.2.RELEASE</version> <version>2.3.2.RELEASE</version>
</dependency> </dependency>

<!-- <!--
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
Expand Down Expand Up @@ -1323,7 +1324,7 @@
<dependency> <dependency>
<groupId>org.apache.directory.server</groupId> <groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId> <artifactId>apacheds-all</artifactId>
<version>1.5.7</version> <version>2.0.0-M24</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.xml.bind</groupId> <groupId>javax.xml.bind</groupId>
Expand Down
5 changes: 5 additions & 0 deletions src/security/ldap/pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.geoserver</groupId> <groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId> <artifactId>gs-main</artifactId>
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
package org.geoserver.security.ldap; package org.geoserver.security.ldap;


import java.io.File; import java.io.File;
import org.apache.directory.server.core.DefaultDirectoryService; import java.util.UUID;
import org.apache.directory.server.core.DirectoryService; import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory;
import org.apache.directory.server.core.factory.DirectoryServiceFactory;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition; import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
import org.apache.directory.server.ldap.LdapServer; import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.protocol.shared.transport.TcpTransport; import org.apache.directory.server.protocol.shared.transport.TcpTransport;
import org.apache.directory.shared.ldap.entry.ServerEntry;
import org.apache.directory.shared.ldap.name.DN;


/** /**
* Helper class for embedded Apache Directory Server. * Helper class for embedded Apache Directory Server.
Expand All @@ -24,8 +26,10 @@
* @author Niels Charlier * @author Niels Charlier
*/ */
public class EmbeddedLdapServer { public class EmbeddedLdapServer {

private final DirectoryService directoryService; private final DirectoryService directoryService;
private final LdapServer ldapServer; private final LdapServer ldapServer;
private static File workingDirectory;


private EmbeddedLdapServer(DirectoryService directoryService, LdapServer ldapServer) { private EmbeddedLdapServer(DirectoryService directoryService, LdapServer ldapServer) {
this.directoryService = directoryService; this.directoryService = directoryService;
Expand All @@ -38,24 +42,31 @@ public static EmbeddedLdapServer newEmbeddedServer(
int port, int port,
boolean allowAnonymousAccess) boolean allowAnonymousAccess)
throws Exception { throws Exception {

DirectoryServiceFactory directoryServiceFactory = new DefaultDirectoryServiceFactory();
DefaultDirectoryService directoryService = new DefaultDirectoryService(); directoryServiceFactory.init("geoserver-ldap" + UUID.randomUUID().toString());
DirectoryService directoryService = directoryServiceFactory.getDirectoryService();
workingDirectory =
new File(
System.getProperty("java.io.tmpdir")
+ "/apacheds-test"
+ UUID.randomUUID().toString());
directoryService.setShutdownHookEnabled(true); directoryService.setShutdownHookEnabled(true);
directoryService.setAllowAnonymousAccess(allowAnonymousAccess); directoryService.setAllowAnonymousAccess(allowAnonymousAccess);
directoryService.setWorkingDirectory(
new File(System.getProperty("java.io.tmpdir") + "/apacheds-test"));
directoryService.getChangeLog().setEnabled(false); directoryService.getChangeLog().setEnabled(false);


JdbmPartition partition = new JdbmPartition(); JdbmPartition partition =
new JdbmPartition(
directoryService.getSchemaManager(), directoryService.getDnFactory());
partition.setId(defaultPartitionName); partition.setId(defaultPartitionName);
partition.setSuffix(defaultPartitionSuffix); partition.setSuffixDn(new Dn(defaultPartitionSuffix));
partition.setPartitionPath(workingDirectory.toURI());
directoryService.addPartition(partition); directoryService.addPartition(partition);


directoryService.startup(); directoryService.startup();


// Inject the apache root entry if it does not already exist // Inject the apache root entry if it does not already exist
if (!directoryService.getAdminSession().exists(partition.getSuffixDn())) { if (!directoryService.getAdminSession().exists(partition.getSuffixDn())) {
ServerEntry entry = directoryService.newEntry(new DN(defaultPartitionSuffix)); Entry entry = directoryService.newEntry(new Dn(defaultPartitionSuffix));
entry.add("objectClass", "top", "domain", "extensibleObject"); entry.add("objectClass", "top", "domain", "extensibleObject");
entry.add("dc", defaultPartitionName); entry.add("dc", defaultPartitionName);
directoryService.getAdminSession().add(entry); directoryService.getAdminSession().add(entry);
Expand All @@ -71,6 +82,10 @@ public static EmbeddedLdapServer newEmbeddedServer(
return new EmbeddedLdapServer(directoryService, ldapServer); return new EmbeddedLdapServer(directoryService, ldapServer);
} }


public void setAllowAnonymousAccess(boolean allowAnonymousAccess) {
directoryService.setAllowAnonymousAccess(allowAnonymousAccess);
}

public void shutdown() throws Exception { public void shutdown() throws Exception {
ldapServer.stop(); ldapServer.stop();
directoryService.shutdown(); directoryService.shutdown();
Expand Down

0 comments on commit c95b86a

Please sign in to comment.