Provide hook to get a client-side version of the DirContext.
This commit is contained in:
parent
1588dbb488
commit
c34db326f8
|
@ -1,14 +1,10 @@
|
||||||
package net.sf.acegisecurity.providers.dao.ldap;
|
package net.sf.acegisecurity.providers.dao.ldap;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.naming.directory.DirContext;
|
import javax.naming.directory.DirContext;
|
||||||
import javax.naming.directory.InitialDirContext;
|
import javax.naming.directory.InitialDirContext;
|
||||||
|
|
||||||
import org.apache.ldap.server.jndi.EnvKeys;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/** Important note: this class merely defines certain
|
/** Important note: this class merely defines certain
|
||||||
|
@ -16,22 +12,34 @@ import junit.framework.TestCase;
|
||||||
*/
|
*/
|
||||||
public class BaseLdapTestCase extends TestCase {
|
public class BaseLdapTestCase extends TestCase {
|
||||||
|
|
||||||
|
// static finalizers, they'd be nice, as LdapTestHelper
|
||||||
|
// never seems to get the chance to cleanup after itself
|
||||||
protected static LdapTestHelper ldapTestHelper = new LdapTestHelper();
|
protected static LdapTestHelper ldapTestHelper = new LdapTestHelper();
|
||||||
|
|
||||||
/** Create and return a Hashtable with standard JNDI settings for our tests. */
|
protected DirContext ctx;
|
||||||
protected Hashtable getEnvironment() {
|
|
||||||
Hashtable env = new Hashtable();
|
protected void setUp() throws NamingException {
|
||||||
env.put( Context.PROVIDER_URL, "ou=system" );
|
ctx = getClientContext();
|
||||||
env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory" );
|
|
||||||
env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
|
|
||||||
env.put( Context.SECURITY_CREDENTIALS, "secret" );
|
|
||||||
env.put( EnvKeys.WKDIR, ldapTestHelper.getTempDirectoryPath() );
|
|
||||||
return env;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create and return a Hashtable with standard JNDI settings for our tests.
|
protected void tearDown() throws NamingException {
|
||||||
* @throws NamingException */
|
ctx.close();
|
||||||
protected DirContext getInitialDirContext() throws NamingException {
|
ctx = null;
|
||||||
return new InitialDirContext( getEnvironment() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected DirContext getClientContext() throws NamingException {
|
||||||
|
Hashtable env = new Hashtable();
|
||||||
|
env.put( Context.PROVIDER_URL, "ldap://localhost:389/ou=system" );
|
||||||
|
env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
|
||||||
|
//env.put( Context.SECURITY_PRINCIPAL, "uid=admin" );
|
||||||
|
//env.put( Context.SECURITY_CREDENTIALS, "secret" );
|
||||||
|
return new InitialDirContext( env );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return The server context for LDAP ops. used for things like addding/removing users. */
|
||||||
|
protected DirContext getServerContext() {
|
||||||
|
return ldapTestHelper.getServerContext();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue