From 1549ec55b19e01fdb5e912aad904f57b9b0ebb86 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Tue, 20 Dec 2005 23:08:54 +0000 Subject: [PATCH] Switch to embedded context version of apache DS (no socket nonsense etc.) --- .../ldap/AbstractLdapServerTestCase.java | 8 +--- .../providers/ldap/LdapTestServer.java | 38 +++++-------------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/core/src/test/java/org/acegisecurity/providers/ldap/AbstractLdapServerTestCase.java b/core/src/test/java/org/acegisecurity/providers/ldap/AbstractLdapServerTestCase.java index 0cb70682b3..9528773c1b 100644 --- a/core/src/test/java/org/acegisecurity/providers/ldap/AbstractLdapServerTestCase.java +++ b/core/src/test/java/org/acegisecurity/providers/ldap/AbstractLdapServerTestCase.java @@ -32,18 +32,12 @@ public abstract class AbstractLdapServerTestCase extends TestCase { // External server config // protected static final String PROVIDER_URL = "ldap://monkeymachine:389/"+ROOT_DN; - -// // Internal server config. -// protected static final String PROVIDER_URL = "ldap://localhost:10389/"+ROOT_DN; - //private static final LdapTestServer SERVER = new LdapTestServer(false); - - // These values should be set for both networked configurations. // protected static final String CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory"; // protected static final Hashtable EXTRA_ENV = new Hashtable(); // Embedded (non-networked) server config - private static final LdapTestServer SERVER = new LdapTestServer(true); + private static final LdapTestServer SERVER = new LdapTestServer(); protected static final String PROVIDER_URL = ROOT_DN; protected static final String CONTEXT_FACTORY = CoreContextFactory.class.getName(); protected static final Hashtable EXTRA_ENV = SERVER.getConfiguration().toJndiEnvironment(); diff --git a/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java b/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java index 01cc0435ed..a0d0dad8b4 100644 --- a/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java +++ b/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java @@ -15,13 +15,10 @@ package org.acegisecurity.providers.ldap; -import org.apache.ldap.server.configuration.StartupConfiguration; import org.apache.ldap.server.configuration.MutableDirectoryPartitionConfiguration; import org.apache.ldap.server.configuration.MutableStartupConfiguration; import org.apache.ldap.server.configuration.Configuration; -import org.apache.ldap.server.configuration.MutableServerStartupConfiguration; import org.apache.ldap.server.jndi.CoreContextFactory; -import org.apache.ldap.server.jndi.ServerContextFactory; import javax.naming.Context; import javax.naming.NamingException; @@ -36,7 +33,6 @@ import java.util.Properties; import java.util.Set; import java.util.HashSet; import java.io.File; -import java.io.IOException; /** * An embedded LDAP test server, complete with test data for running the @@ -51,7 +47,7 @@ public class LdapTestServer { private DirContext serverContext; - private StartupConfiguration cfg; + private MutableStartupConfiguration cfg; // Move the working dir to the temp directory private File workingDir = new File( System.getProperty("java.io.tmpdir") @@ -62,28 +58,19 @@ public class LdapTestServer { /** * Starts up and configures ApacheDS. - * - * @param embedded if false the server will listen for connections on port 10389 - * */ - public LdapTestServer(boolean embedded) { - startLdapServer(embedded); + public LdapTestServer() { + startLdapServer(); createManagerUser(); initTestData(); } //~ Methods ================================================================ + private void startLdapServer() { - private void startLdapServer(boolean embedded) { - - if(embedded) { - cfg = new MutableStartupConfiguration(); - ((MutableStartupConfiguration)cfg).setWorkingDirectory(workingDir); - } else { - cfg = new MutableServerStartupConfiguration(); - ((MutableServerStartupConfiguration)cfg).setWorkingDirectory(workingDir); - } + cfg = new MutableStartupConfiguration(); + ((MutableStartupConfiguration)cfg).setWorkingDirectory(workingDir); System.out.println("Working directory is " + workingDir.getAbsolutePath()); @@ -92,8 +79,7 @@ public class LdapTestServer { Properties env = new Properties(); env.setProperty( Context.PROVIDER_URL, "dc=acegisecurity,dc=org" ); - env.setProperty( Context.INITIAL_CONTEXT_FACTORY, - embedded ? CoreContextFactory.class.getName() : ServerContextFactory.class.getName() ); + env.setProperty( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName()); env.putAll( cfg.toJndiEnvironment() ); try { @@ -229,13 +215,7 @@ public class LdapTestServer { Set partitions = new HashSet(); partitions.add(acegiDit); - if(cfg instanceof MutableServerStartupConfiguration) { - MutableServerStartupConfiguration serverCfg = (MutableServerStartupConfiguration)cfg; - serverCfg.setLdapPort(10389); - serverCfg.setContextPartitionConfigurations(partitions); - } else { - ((MutableStartupConfiguration)cfg).setContextPartitionConfigurations(partitions); - } + cfg.setContextPartitionConfigurations(partitions); } public Configuration getConfiguration() { @@ -243,7 +223,7 @@ public class LdapTestServer { } public static void main(String[] args) { - LdapTestServer server = new LdapTestServer(false); + LdapTestServer server = new LdapTestServer(); } }