org.acegisecurity.ldap
Class DefaultInitialDirContextFactory

java.lang.Object
  extended by org.acegisecurity.ldap.DefaultInitialDirContextFactory
All Implemented Interfaces:
InitialDirContextFactory, MessageSourceAware

public class DefaultInitialDirContextFactory
extends Object
implements InitialDirContextFactory, MessageSourceAware

Encapsulates the information for connecting to an LDAP server and provides an access point for obtaining DirContext references.

The directory location is configured using by setting the constructor argument providerUrl. This should be in the form ldap://monkeymachine.co.uk:389/dc=acegisecurity,dc=org. The Sun JNDI provider also supports lists of space-separated URLs, each of which will be tried in turn until a connection is obtained.

To obtain an initial context, the client calls the newInitialDirContext method. There are two signatures - one with no arguments and one which allows binding with a specific username and password.

The no-args version will bind anonymously unless a manager login has been configured using the properties managerDn and managerPassword, in which case it will bind as the manager user.

Connection pooling is enabled by default for anonymous or manager connections, but not when binding as a specific user.

Version:
$Id: DefaultInitialDirContextFactory.java 1603 2006-08-25 16:03:50Z luke_t $
Author:
Robert Sanders, Luke Taylor
See Also:
The Java tutorial's guide to LDAP connection pooling

Field Summary
protected  MessageSourceAccessor messages
           
 
Constructor Summary
DefaultInitialDirContextFactory(String providerUrl)
          Create and initialize an instance to the LDAP url provided
 
Method Summary
protected  Hashtable getEnvironment()
          Sets up the environment parameters for creating a new context.
 String getRootDn()
          Returns the root DN of the configured provider URL.
 DirContext newInitialDirContext()
          Connects anonymously unless a manager user has been specified, in which case it will bind as the manager.
 DirContext newInitialDirContext(String username, String password)
          Provides an initial context by binding as a specific user.
 void setAuthenticationType(String authenticationType)
           
 void setExtraEnvVars(Map extraEnvVars)
          Sets any custom environment variables which will be added to the those returned by the getEnvironment method.
 void setInitialContextFactory(String initialContextFactory)
           
 void setManagerDn(String managerDn)
          Sets the directory user to authenticate as when obtaining a context using the newInitialDirContext() method.
 void setManagerPassword(String managerPassword)
          Sets the password which will be used in combination with the manager DN.
 void setMessageSource(MessageSource messageSource)
           
 void setUseConnectionPool(boolean useConnectionPool)
          Connection pooling is enabled by default for anonymous or "manager" connections when using the default Sun provider.
 void setUseLdapContext(boolean useLdapContext)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messages

protected MessageSourceAccessor messages
Constructor Detail

DefaultInitialDirContextFactory

public DefaultInitialDirContextFactory(String providerUrl)
Create and initialize an instance to the LDAP url provided

Parameters:
providerUrl - a String of the form ldap://localhost:389/base_dn
Method Detail

getEnvironment

protected Hashtable getEnvironment()
Sets up the environment parameters for creating a new context.

Returns:
the Hashtable describing the base DirContext that will be created, minus the username/password if any.

getRootDn

public String getRootDn()
Returns the root DN of the configured provider URL. For example, if the URL is ldap://monkeymachine.co.uk:389/dc=acegisecurity,dc=org the value will be dc=acegisecurity,dc=org.

Specified by:
getRootDn in interface InitialDirContextFactory
Returns:
the root DN calculated from the path of the LDAP url.

newInitialDirContext

public DirContext newInitialDirContext()
Connects anonymously unless a manager user has been specified, in which case it will bind as the manager.

Specified by:
newInitialDirContext in interface InitialDirContextFactory
Returns:
the resulting context object.

newInitialDirContext

public DirContext newInitialDirContext(String username,
                                       String password)
Description copied from interface: InitialDirContextFactory
Provides an initial context by binding as a specific user.

Specified by:
newInitialDirContext in interface InitialDirContextFactory
Parameters:
username - the user to authenticate as when obtaining the context.
password - the user's password.
Returns:
An initial context for the LDAP directory

setAuthenticationType

public void setAuthenticationType(String authenticationType)

setExtraEnvVars

public void setExtraEnvVars(Map extraEnvVars)
Sets any custom environment variables which will be added to the those returned by the getEnvironment method.

Parameters:
extraEnvVars - extra environment variables to be added at config time.

setInitialContextFactory

public void setInitialContextFactory(String initialContextFactory)

setManagerDn

public void setManagerDn(String managerDn)
Sets the directory user to authenticate as when obtaining a context using the newInitialDirContext() method. If no name is supplied then the context will be obtained anonymously.

Parameters:
managerDn - The name of the "manager" user for default authentication.

setManagerPassword

public void setManagerPassword(String managerPassword)
Sets the password which will be used in combination with the manager DN.

Parameters:
managerPassword - The "manager" user's password.

setMessageSource

public void setMessageSource(MessageSource messageSource)
Specified by:
setMessageSource in interface MessageSourceAware

setUseConnectionPool

public void setUseConnectionPool(boolean useConnectionPool)
Connection pooling is enabled by default for anonymous or "manager" connections when using the default Sun provider. To disable all connection pooling, set this property to false.

Parameters:
useConnectionPool - whether to pool connections for non-specific users.

setUseLdapContext

public void setUseLdapContext(boolean useLdapContext)


Copyright © 2004-2006 Acegi Technology Pty Limited. All Rights Reserved.