SEC-1075: Update the embedded LDAP server to use Apache DS 1.5. Updated to use the new 1.5.5 release for the embedded server.

This commit is contained in:
Luke Taylor
2009-09-01 23:21:44 +00:00
parent 53baac2fd9
commit 245fc96137
8 changed files with 182 additions and 200 deletions

View File

@@ -14,24 +14,14 @@
*/
package org.springframework.security.ldap;
import java.util.HashSet;
import java.util.Set;
import javax.naming.Binding;
import javax.naming.ContextNotEmptyException;
import javax.naming.Name;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import org.apache.directory.server.configuration.MutableServerStartupConfiguration;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration;
import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
import org.junit.After;
import org.junit.AfterClass;
@@ -56,35 +46,11 @@ public abstract class AbstractLdapIntegrationTests {
protected AbstractLdapIntegrationTests() {
}
@SuppressWarnings("unchecked")
@BeforeClass
public static void startServer() throws Exception {
shutdownRunningServers();
MutableBTreePartitionConfiguration partition = new MutableBTreePartitionConfiguration();
partition.setName("springsecurity");
Attributes rootAttributes = new BasicAttributes("dc", "springsecurity");
Attribute a = new BasicAttribute("objectClass");
a.add("top");
a.add("domain");
a.add("extensibleObject");
rootAttributes.put(a);
partition.setContextEntry(rootAttributes);
partition.setSuffix("dc=springframework,dc=org");
Set partitions = new HashSet();
partitions.add(partition);
MutableServerStartupConfiguration cfg = new MutableServerStartupConfiguration();
cfg.setLdapPort(53389);
cfg.setShutdownHookEnabled(false);
cfg.setExitVmOnShutdown(false);
cfg.setContextPartitionConfigurations(partitions);
contextSource = new DefaultSpringSecurityContextSource("ldap://127.0.0.1:53389/dc=springframework,dc=org");
((DefaultSpringSecurityContextSource)contextSource).afterPropertiesSet();
server = new ApacheDSContainer(cfg, contextSource, "classpath:test-server.ldif");
server = new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif");
server.afterPropertiesSet();
}
@@ -93,20 +59,8 @@ public abstract class AbstractLdapIntegrationTests {
if (server != null) {
server.stop();
}
shutdownRunningServers();
}
private static void shutdownRunningServers() throws NamingException {
DirectoryService ds = DirectoryService.getInstance();
if (ds.isStarted()) {
System.out.println("WARNING: Discovered running DirectoryService with configuration: " + ds.getConfiguration().getStartupConfiguration().toString());
System.out.println("Shutting it down...");
ds.shutdown();
}
}
@Before
public void onSetUp() throws Exception {
}
@@ -127,7 +81,7 @@ public abstract class AbstractLdapIntegrationTests {
try {
clearSubContexts(ctx, startingPoint);
LdifFileLoader loader = new LdifFileLoader(ctx, ldifs.getFile().getAbsolutePath());
LdifFileLoader loader = new LdifFileLoader(server.getService().getAdminSession(), ldifs.getFile().getAbsolutePath());
loader.execute();
} finally {
ctx.close();

View File

@@ -0,0 +1,27 @@
package org.springframework.security.ldap.server;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.junit.Test;
/**
* Useful for debugging the container by itself.
*
* @author Luke Taylor
* @version $Id$
* @since 3.0
*/
public class ApacheDSContainerTests {
@Test
public void successfulStartupAndShutdown() throws Exception {
LdapDN people = new LdapDN("ou=people,dc=springframework,dc=org");
people.toString();
// ApacheDSContainer server = new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif");
// server.afterPropertiesSet();
//
// server.getService().getAdminSession().lookup(people);
//
// server.stop();
}
}