Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDAP Security : upgrade to 1.3.2, fix busy port issue
- Loading branch information
1 parent
005e337
commit ede695e
Showing
8 changed files
with
281 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/security/ldap/src/test/java/org/geoserver/security/ldap/EmbeddedLdapServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved | ||
* (c) 2001 - 2013 OpenPlans | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.security.ldap; | ||
|
||
import org.apache.directory.server.core.DefaultDirectoryService; | ||
import org.apache.directory.server.core.DirectoryService; | ||
import org.apache.directory.server.core.entry.ServerEntry; | ||
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition; | ||
import org.apache.directory.server.ldap.LdapServer; | ||
import org.apache.directory.server.protocol.shared.transport.TcpTransport; | ||
import org.apache.directory.shared.ldap.name.LdapDN; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Helper class for embedded Apache Directory Server. | ||
* | ||
* copied and modified from org.springframework.ldap.test.EmbeddedLdapServer | ||
* to allow anonymous access (there was no alternative way) | ||
* | ||
* @author Mattias Hellborg Arthursson | ||
* @author Niels Charlier | ||
*/ | ||
public class EmbeddedLdapServer { | ||
private final DirectoryService directoryService; | ||
private final LdapServer ldapServer; | ||
|
||
private EmbeddedLdapServer(DirectoryService directoryService, | ||
LdapServer ldapServer) { | ||
this.directoryService = directoryService; | ||
this.ldapServer = ldapServer; | ||
} | ||
|
||
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName, String defaultPartitionSuffix, int port, | ||
boolean allowAnonymousAccess) | ||
throws Exception{ | ||
|
||
DefaultDirectoryService directoryService = new DefaultDirectoryService(); | ||
directoryService.setShutdownHookEnabled(true); | ||
directoryService.setAllowAnonymousAccess(allowAnonymousAccess); | ||
directoryService.setWorkingDirectory(new File(System.getProperty("java.io.tmpdir") + "/apacheds-test")); | ||
directoryService.getChangeLog().setEnabled( false ); | ||
|
||
JdbmPartition partition = new JdbmPartition(); | ||
partition.setId(defaultPartitionName); | ||
partition.setSuffix(defaultPartitionSuffix); | ||
directoryService.addPartition(partition); | ||
|
||
directoryService.startup(); | ||
|
||
// Inject the apache root entry if it does not already exist | ||
if ( !directoryService.getAdminSession().exists( partition.getSuffixDn() ) ) | ||
{ | ||
ServerEntry entry = directoryService.newEntry(new LdapDN(defaultPartitionSuffix)); | ||
entry.add("objectClass", "top", "domain", "extensibleObject"); | ||
entry.add("dc", defaultPartitionName); | ||
directoryService.getAdminSession().add( entry ); | ||
} | ||
|
||
LdapServer ldapServer = new LdapServer(); | ||
ldapServer.setDirectoryService(directoryService); | ||
|
||
TcpTransport ldapTransport = new TcpTransport(port); | ||
ldapServer.setTransports( ldapTransport ); | ||
ldapServer.start(); | ||
|
||
return new EmbeddedLdapServer(directoryService, ldapServer); | ||
} | ||
|
||
public void shutdown() throws Exception { | ||
ldapServer.stop(); | ||
directoryService.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.