Switch to embedded context version of apache DS (no socket nonsense etc.)

This commit is contained in:
Luke Taylor 2005-12-20 23:08:54 +00:00
parent e33edef1c8
commit 1549ec55b1
2 changed files with 10 additions and 36 deletions

View File

@ -32,18 +32,12 @@ public abstract class AbstractLdapServerTestCase extends TestCase {
// External server config // External server config
// protected static final String PROVIDER_URL = "ldap://monkeymachine:389/"+ROOT_DN; // 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 String CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
// protected static final Hashtable EXTRA_ENV = new Hashtable(); // protected static final Hashtable EXTRA_ENV = new Hashtable();
// Embedded (non-networked) server config // 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 PROVIDER_URL = ROOT_DN;
protected static final String CONTEXT_FACTORY = CoreContextFactory.class.getName(); protected static final String CONTEXT_FACTORY = CoreContextFactory.class.getName();
protected static final Hashtable EXTRA_ENV = SERVER.getConfiguration().toJndiEnvironment(); protected static final Hashtable EXTRA_ENV = SERVER.getConfiguration().toJndiEnvironment();

View File

@ -15,13 +15,10 @@
package org.acegisecurity.providers.ldap; 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.MutableDirectoryPartitionConfiguration;
import org.apache.ldap.server.configuration.MutableStartupConfiguration; import org.apache.ldap.server.configuration.MutableStartupConfiguration;
import org.apache.ldap.server.configuration.Configuration; 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.CoreContextFactory;
import org.apache.ldap.server.jndi.ServerContextFactory;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.NamingException; import javax.naming.NamingException;
@ -36,7 +33,6 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.io.File; import java.io.File;
import java.io.IOException;
/** /**
* An embedded LDAP test server, complete with test data for running the * An embedded LDAP test server, complete with test data for running the
@ -51,7 +47,7 @@ public class LdapTestServer {
private DirContext serverContext; private DirContext serverContext;
private StartupConfiguration cfg; private MutableStartupConfiguration cfg;
// Move the working dir to the temp directory // Move the working dir to the temp directory
private File workingDir = new File( System.getProperty("java.io.tmpdir") private File workingDir = new File( System.getProperty("java.io.tmpdir")
@ -62,28 +58,19 @@ public class LdapTestServer {
/** /**
* Starts up and configures ApacheDS. * Starts up and configures ApacheDS.
*
* @param embedded if false the server will listen for connections on port 10389
*
*/ */
public LdapTestServer(boolean embedded) { public LdapTestServer() {
startLdapServer(embedded); startLdapServer();
createManagerUser(); createManagerUser();
initTestData(); initTestData();
} }
//~ Methods ================================================================ //~ Methods ================================================================
private void startLdapServer() {
private void startLdapServer(boolean embedded) { cfg = new MutableStartupConfiguration();
((MutableStartupConfiguration)cfg).setWorkingDirectory(workingDir);
if(embedded) {
cfg = new MutableStartupConfiguration();
((MutableStartupConfiguration)cfg).setWorkingDirectory(workingDir);
} else {
cfg = new MutableServerStartupConfiguration();
((MutableServerStartupConfiguration)cfg).setWorkingDirectory(workingDir);
}
System.out.println("Working directory is " + workingDir.getAbsolutePath()); System.out.println("Working directory is " + workingDir.getAbsolutePath());
@ -92,8 +79,7 @@ public class LdapTestServer {
Properties env = new Properties(); Properties env = new Properties();
env.setProperty( Context.PROVIDER_URL, "dc=acegisecurity,dc=org" ); env.setProperty( Context.PROVIDER_URL, "dc=acegisecurity,dc=org" );
env.setProperty( Context.INITIAL_CONTEXT_FACTORY, env.setProperty( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName());
embedded ? CoreContextFactory.class.getName() : ServerContextFactory.class.getName() );
env.putAll( cfg.toJndiEnvironment() ); env.putAll( cfg.toJndiEnvironment() );
try { try {
@ -229,13 +215,7 @@ public class LdapTestServer {
Set partitions = new HashSet(); Set partitions = new HashSet();
partitions.add(acegiDit); partitions.add(acegiDit);
if(cfg instanceof MutableServerStartupConfiguration) { cfg.setContextPartitionConfigurations(partitions);
MutableServerStartupConfiguration serverCfg = (MutableServerStartupConfiguration)cfg;
serverCfg.setLdapPort(10389);
serverCfg.setContextPartitionConfigurations(partitions);
} else {
((MutableStartupConfiguration)cfg).setContextPartitionConfigurations(partitions);
}
} }
public Configuration getConfiguration() { public Configuration getConfiguration() {
@ -243,7 +223,7 @@ public class LdapTestServer {
} }
public static void main(String[] args) { public static void main(String[] args) {
LdapTestServer server = new LdapTestServer(false); LdapTestServer server = new LdapTestServer();
} }
} }