org.jasig.portal.ldap
Class LdapServerImpl

java.lang.Object
  extended by org.jasig.portal.ldap.LdapServerImpl
All Implemented Interfaces:
ILdapServer

public class LdapServerImpl
extends java.lang.Object
implements ILdapServer

Default implementation of ILdapServer.

Version:
$Revision: 1.2 $ $Date: 2004/11/17 19:09:45 $
Author:
edalquist@unicon.net, andrew.petro@yale.edu

Field Summary
private static java.lang.String DEFAULT_CXT_FACTORY
          Name of the class that is the default context factory which will be used if not overridden.
private  java.util.Hashtable env
          Environment, populated at construction.
private  java.lang.String ldapBaseDn
           
private  java.lang.String ldapName
          Name of this LDAP server for identification and debugging purposes.
private  java.lang.String ldapUidAttribute
          The attribute by which we query using uids.
private  org.apache.commons.logging.Log log
           
 
Constructor Summary
LdapServerImpl(java.lang.String name, java.lang.String url, java.lang.String baseDn, java.lang.String uidAttribute, java.lang.String managerDn, java.lang.String managerPw, java.lang.String initialContextFactory)
          Instantiate an LdapServerImpl using somewhat abtstracted configuration over that present in the more detailed constructor.
LdapServerImpl(java.lang.String name, java.lang.String host, java.lang.String port, java.lang.String baseDn, java.lang.String uidAttribute, java.lang.String managerDn, java.lang.String managerPw, boolean useSsl, java.lang.String initialContextFactory)
          Instantiate an LdapServerImpl with the given low-level configuration.
 
Method Summary
private static java.lang.String checkNull(java.lang.String chkStr, java.lang.String defStr)
          Returns the chckStr argument unless the chkStr argument is null, in which case returns the defStr (default) argument.
private static java.lang.String constructLdapUrl(java.lang.String host, java.lang.String port, boolean useSsl)
          Construct a URL for an LDAP server.
 java.lang.String getBaseDN()
          Gets the base DN used to search the LDAP directory context.
 javax.naming.directory.DirContext getConnection()
          Gets an LDAP directory context.
 java.lang.String getUidAttribute()
          Gets the uid attribute used to search the LDAP directory context.
 void releaseConnection(javax.naming.directory.DirContext conn)
          Releases an LDAP directory context.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log

DEFAULT_CXT_FACTORY

private static final java.lang.String DEFAULT_CXT_FACTORY
Name of the class that is the default context factory which will be used if not overridden.

See Also:
Constant Field Values

ldapName

private final java.lang.String ldapName
Name of this LDAP server for identification and debugging purposes.


ldapBaseDn

private final java.lang.String ldapBaseDn

ldapUidAttribute

private final java.lang.String ldapUidAttribute
The attribute by which we query using uids.


env

private java.util.Hashtable env
Environment, populated at construction.

Constructor Detail

LdapServerImpl

public LdapServerImpl(java.lang.String name,
                      java.lang.String url,
                      java.lang.String baseDn,
                      java.lang.String uidAttribute,
                      java.lang.String managerDn,
                      java.lang.String managerPw,
                      java.lang.String initialContextFactory)
Instantiate an LdapServerImpl using somewhat abtstracted configuration over that present in the more detailed constructor. You communicate a desire to use SSL to this method by using an ldaps//... URL rather than an ldap//... url.

Parameters:
name - mnemonic name for this Ldap server instance
url - URL of LDAP server
baseDn -
uidAttribute - attribute against which to match for uid queries
managerDn - principal for LDAP authentication, null implies no authentication
managerPw - password for LDAP authentication, null implies no authentication
initialContextFactory - the name of the class to use to instantiate the context.

LdapServerImpl

public LdapServerImpl(java.lang.String name,
                      java.lang.String host,
                      java.lang.String port,
                      java.lang.String baseDn,
                      java.lang.String uidAttribute,
                      java.lang.String managerDn,
                      java.lang.String managerPw,
                      boolean useSsl,
                      java.lang.String initialContextFactory)
Instantiate an LdapServerImpl with the given low-level configuration. Using this constructor has the advantage of doing some argument checking on the port number.

Parameters:
name - mnemonic name for this Ldap server instance
host - host of the LDAP server
port - port number. null implies default of 389
baseDn -
uidAttribute - attribute against which to match for uid queries
managerDn - principal for LDAP authentication, null implies no authentication
managerPw - password for LDAP authentication
useSsl - true if we should use SSL, false otherwise.
initialContextFactory - name of the class to use for building init context, null defaults to com.sun.jndi.ldap.LdapCtxFactory
Throws:
java.lang.IllegalArgumentException - when arguments do not specify valid server
Method Detail

constructLdapUrl

private static java.lang.String constructLdapUrl(java.lang.String host,
                                                 java.lang.String port,
                                                 boolean useSsl)
Construct a URL for an LDAP server.

Parameters:
host -
port -
useSsl -
Returns:
URL constructed from the arguments

checkNull

private static java.lang.String checkNull(java.lang.String chkStr,
                                          java.lang.String defStr)
Returns the chckStr argument unless the chkStr argument is null, in which case returns the defStr (default) argument.

Parameters:
chkStr - - String to check
defStr - - fallback default for when the string to check was null
Returns:
chkStr if not null, defStr if chkStr was null

getConnection

public javax.naming.directory.DirContext getConnection()
                                                throws javax.naming.NamingException
Description copied from interface: ILdapServer
Gets an LDAP directory context.

Specified by:
getConnection in interface ILdapServer
Returns:
an LDAP directory context object.
Throws:
javax.naming.NamingException - If there is a problem connecting to the ldap server.

getBaseDN

public java.lang.String getBaseDN()
Description copied from interface: ILdapServer
Gets the base DN used to search the LDAP directory context.

Specified by:
getBaseDN in interface ILdapServer
Returns:
a DN to use as reference point or context for queries

getUidAttribute

public java.lang.String getUidAttribute()
Description copied from interface: ILdapServer
Gets the uid attribute used to search the LDAP directory context.

Specified by:
getUidAttribute in interface ILdapServer
Returns:
a DN to use as reference point or context for queries

releaseConnection

public void releaseConnection(javax.naming.directory.DirContext conn)
Description copied from interface: ILdapServer
Releases an LDAP directory context.

Specified by:
releaseConnection in interface ILdapServer
Parameters:
conn - an LDAP directory context object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object