|
@@ -14,15 +14,24 @@
|
|
|
*/
|
|
|
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;
|
|
@@ -31,8 +40,7 @@ import org.junit.BeforeClass;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.ldap.core.DistinguishedName;
|
|
|
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
|
|
|
-import org.springframework.security.config.BeanIds;
|
|
|
-import org.springframework.security.util.InMemoryXmlApplicationContext;
|
|
|
+import org.springframework.security.ldap.server.ApacheDSContainer;
|
|
|
|
|
|
/**
|
|
|
* Based on class borrowed from Spring Ldap project.
|
|
@@ -41,22 +49,48 @@ import org.springframework.security.util.InMemoryXmlApplicationContext;
|
|
|
* @version $Id$
|
|
|
*/
|
|
|
public abstract class AbstractLdapIntegrationTests {
|
|
|
- private static InMemoryXmlApplicationContext appContext;
|
|
|
+// private static InMemoryXmlApplicationContext appContext;
|
|
|
+ private static ApacheDSContainer server;
|
|
|
+ private static BaseLdapPathContextSource contextSource;
|
|
|
|
|
|
protected AbstractLdapIntegrationTests() {
|
|
|
}
|
|
|
|
|
|
@BeforeClass
|
|
|
- public static void loadContext() throws NamingException {
|
|
|
+ public static void startServer() throws Exception {
|
|
|
shutdownRunningServers();
|
|
|
- appContext = new InMemoryXmlApplicationContext("<ldap-server port='53389' ldif='classpath:test-server.ldif'/>");
|
|
|
-
|
|
|
+ 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.afterPropertiesSet();
|
|
|
}
|
|
|
|
|
|
@AfterClass
|
|
|
- public static void closeContext() throws Exception {
|
|
|
- if(appContext != null) {
|
|
|
- appContext.close();
|
|
|
+ public static void stopServer() throws Exception {
|
|
|
+ if (server != null) {
|
|
|
+ server.stop();
|
|
|
}
|
|
|
shutdownRunningServers();
|
|
|
}
|
|
@@ -100,7 +134,7 @@ public abstract class AbstractLdapIntegrationTests {
|
|
|
}
|
|
|
|
|
|
public BaseLdapPathContextSource getContextSource() {
|
|
|
- return (BaseLdapPathContextSource)appContext.getBean(BeanIds.CONTEXT_SOURCE);
|
|
|
+ return contextSource;
|
|
|
}
|
|
|
|
|
|
|