org.esupportail.cas.server.handlers.ldap
Class LdapServer

java.lang.Object
  extended by org.esupportail.cas.server.util.log.Debug
      extended by org.esupportail.cas.server.util.Server
          extended by org.esupportail.cas.server.handlers.ldap.LdapServer
Direct Known Subclasses:
BindLdapServer, FastBindLdapServer

public abstract class LdapServer
extends Server

This abstract class implements an LDAP server class, inherited by BindLdapServer and FastBindLdapServer.

Author:
Pascal Aubry , Jean-Baptiste Daniel , Patrik Schnellmann - SWITCH

Field Summary
private static java.lang.String[] INPUT_TOKENS
          A String array used to store input tokens (to be replaced).
private  boolean secured
          true for a secure access to the LDAP directory, false otherwise.
private  boolean skipReferrals
          skip Referrals, useful when using Active Directory
private  java.lang.String url
          the URL of the LDAP directory.
 
Fields inherited from class org.esupportail.cas.server.util.Server
AUTHENTICATE_FAILURE, AUTHENTICATE_NOAUTH, AUTHENTICATE_SUCCESS, CONNECT_FAILURE, CONNECT_NOAUTH, CONNECT_SUCCESS
 
Constructor Summary
LdapServer(java.lang.Boolean handlerDebug, RedundantHandler handler, org.dom4j.Element serverElement)
          Constructor.
 
Method Summary
protected  javax.naming.directory.DirContext connect(java.lang.String bindDn, java.lang.String bindPassword)
          Connect to the LDAP server using specified username and password.
protected  boolean connectAndClose(java.lang.String bindDn, java.lang.String bindPassword)
          Connect to the LDAP server using specified username and password and immediatly close the connection.
protected  java.lang.String replaceTokens(java.lang.String filter, java.lang.String username)
          Take a filter (from CASGenericHandler configuration) and a username, and replace tokens in the filter by their equivalents in the username.
 
Methods inherited from class org.esupportail.cas.server.util.Server
authenticate, getConnectError, getHandler, getServerSubElementContent, setConnectError
 
Methods inherited from class org.esupportail.cas.server.util.log.Debug
checkClass, elementDebugValue, isDebug, setDebug, trace, trace, traceBegin, traceEnd, traceEnd, traceEnd, traceThrow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INPUT_TOKENS

private static final java.lang.String[] INPUT_TOKENS
A String array used to store input tokens (to be replaced).


secured

private boolean secured
true for a secure access to the LDAP directory, false otherwise.


skipReferrals

private boolean skipReferrals
skip Referrals, useful when using Active Directory


url

private java.lang.String url
the URL of the LDAP directory.

Constructor Detail

LdapServer

public LdapServer(java.lang.Boolean handlerDebug,
                  RedundantHandler handler,
                  org.dom4j.Element serverElement)
           throws java.lang.Exception
Constructor.

Parameters:
handlerDebug - debugging mode of the handler
handler - the handler the server will be used by
serverElement - the XML element that declares the server
Throws:
java.lang.Exception - Exception
Method Detail

connect

protected final javax.naming.directory.DirContext connect(java.lang.String bindDn,
                                                          java.lang.String bindPassword)
Connect to the LDAP server using specified username and password.

Parameters:
bindDn - the DN to use for the connection
bindPassword - the associated password
Returns:
a Connection object on success, null on error. When the function returns false, the error code can be retrieved with the connectError() method.

connectAndClose

protected final boolean connectAndClose(java.lang.String bindDn,
                                        java.lang.String bindPassword)
Connect to the LDAP server using specified username and password and immediatly close the connection. The error code can be retrieved with the connectError() method.

Parameters:
bindDn - the DN to use for the connection
bindPassword - the associated password
Returns:
true if the connection succeeded, false otherwise.

replaceTokens

protected final java.lang.String replaceTokens(java.lang.String filter,
                                               java.lang.String username)
Take a filter (from CASGenericHandler configuration) and a username, and replace tokens in the filter by their equivalents in the username. The rules to replace tokens are the following ones: - %%: % - %u: user - %U: user portion of %u (%U = test when %u = test@domain.tld) - %d: domain portion of %u (%d = domain.tld when %u = test@domain.tld) - %1-9: domain tokens (%1 = tld, %2 = domain when %d = domain.tld)

Parameters:
username - a username (such as test@domain.com)
filter - a filter string containing tokens to be replaced
Returns:
a string corresponding to the input filter, where the predefined tokens have been replaced by their equivalents.