Package edu.vt.middleware.ldap.handler
Class AbstractConnectionHandler
- java.lang.Object
-
- edu.vt.middleware.ldap.handler.AbstractConnectionHandler
-
- All Implemented Interfaces:
ConnectionHandler
- Direct Known Subclasses:
DefaultConnectionHandler
public abstract class AbstractConnectionHandler extends java.lang.Object implements ConnectionHandler
AbstractConnectionHandler
provides a basic implementation for other connection handlers to inherit.- Version:
- $Revision: 2397 $
- Author:
- Middleware Services
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface edu.vt.middleware.ldap.handler.ConnectionHandler
ConnectionHandler.ConnectionStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected LdapConfig
config
Ldap configuration.protected java.lang.Class<?>[]
connectionRetryExceptions
Exception types to retry connections on.protected ConnectionHandler.ConnectionStrategy
connectionStrategy
Ldap connection strategy.protected javax.naming.ldap.LdapContext
context
Ldap context.protected org.apache.commons.logging.Log
logger
Log for this class.
-
Constructor Summary
Constructors Constructor Description AbstractConnectionHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Close a connection to an LDAP.void
connect(java.lang.String dn, java.lang.Object credential)
Open a connection to an LDAP.protected abstract void
connectInternal(java.lang.String authtype, java.lang.String dn, java.lang.Object credential, java.util.Hashtable<java.lang.String,java.lang.Object> env)
Create the initial ldap context and prepare the connection for use.protected edu.vt.middleware.ldap.handler.AbstractConnectionHandler.ConnectionCount
getConnectionCount()
Returns the connection count.java.lang.Class<?>[]
getConnectionRetryExceptions()
This returns the exception types to retry connections on.ConnectionHandler.ConnectionStrategy
getConnectionStrategy()
Returns the connection strategy.LdapConfig
getLdapConfig()
Returns the ldap configuration.javax.naming.ldap.LdapContext
getLdapContext()
Returns an ldap context to use for ldap operations.boolean
isConnected()
Returns whether the underlying context has been established.abstract ConnectionHandler
newInstance()
Returns a separate instance of this connection handler with the same underlying ldap configuration.protected java.lang.String[]
parseLdapUrl(java.lang.String ldapUrl, ConnectionHandler.ConnectionStrategy strategy)
Parses the supplied ldap url and splits it into separate URLs if it is space delimited.protected void
setConnectionCount(edu.vt.middleware.ldap.handler.AbstractConnectionHandler.ConnectionCount cc)
Sets the connection count.void
setConnectionRetryExceptions(java.lang.Class<?>[] exceptions)
This sets the exception types to retry connections on.void
setConnectionStrategy(ConnectionHandler.ConnectionStrategy strategy)
Sets the connection strategy.void
setLdapConfig(LdapConfig lc)
Sets the ldap configuration.
-
-
-
Field Detail
-
logger
protected final org.apache.commons.logging.Log logger
Log for this class.
-
config
protected LdapConfig config
Ldap configuration.
-
context
protected javax.naming.ldap.LdapContext context
Ldap context.
-
connectionStrategy
protected ConnectionHandler.ConnectionStrategy connectionStrategy
Ldap connection strategy.
-
connectionRetryExceptions
protected java.lang.Class<?>[] connectionRetryExceptions
Exception types to retry connections on.
-
-
Method Detail
-
getConnectionCount
protected edu.vt.middleware.ldap.handler.AbstractConnectionHandler.ConnectionCount getConnectionCount()
Returns the connection count.- Returns:
- connection count
-
setConnectionCount
protected void setConnectionCount(edu.vt.middleware.ldap.handler.AbstractConnectionHandler.ConnectionCount cc)
Sets the connection count.- Parameters:
cc
- connection count
-
getConnectionStrategy
public ConnectionHandler.ConnectionStrategy getConnectionStrategy()
Returns the connection strategy.- Specified by:
getConnectionStrategy
in interfaceConnectionHandler
- Returns:
- strategy for making connections
-
setConnectionStrategy
public void setConnectionStrategy(ConnectionHandler.ConnectionStrategy strategy)
Sets the connection strategy.- Specified by:
setConnectionStrategy
in interfaceConnectionHandler
- Parameters:
strategy
- for making connections
-
getConnectionRetryExceptions
public java.lang.Class<?>[] getConnectionRetryExceptions()
This returns the exception types to retry connections on.- Specified by:
getConnectionRetryExceptions
in interfaceConnectionHandler
- Returns:
Class[]
-
setConnectionRetryExceptions
public void setConnectionRetryExceptions(java.lang.Class<?>[] exceptions)
This sets the exception types to retry connections on.- Specified by:
setConnectionRetryExceptions
in interfaceConnectionHandler
- Parameters:
exceptions
-Class[]
-
getLdapConfig
public LdapConfig getLdapConfig()
Returns the ldap configuration.- Specified by:
getLdapConfig
in interfaceConnectionHandler
- Returns:
- ldap config
-
setLdapConfig
public void setLdapConfig(LdapConfig lc)
Sets the ldap configuration.- Specified by:
setLdapConfig
in interfaceConnectionHandler
- Parameters:
lc
- ldap config
-
getLdapContext
public javax.naming.ldap.LdapContext getLdapContext()
Returns an ldap context to use for ldap operations.ConnectionHandler.connect(String, Object)
must be called prior to invoking this.- Specified by:
getLdapContext
in interfaceConnectionHandler
- Returns:
- ldap context
-
connect
public void connect(java.lang.String dn, java.lang.Object credential) throws javax.naming.NamingException
Open a connection to an LDAP.- Specified by:
connect
in interfaceConnectionHandler
- Parameters:
dn
- to attempt bind withcredential
- to attempt bind with- Throws:
javax.naming.NamingException
- if an LDAP error occurs
-
connectInternal
protected abstract void connectInternal(java.lang.String authtype, java.lang.String dn, java.lang.Object credential, java.util.Hashtable<java.lang.String,java.lang.Object> env) throws javax.naming.NamingException
Create the initial ldap context and prepare the connection for use.- Parameters:
authtype
- security mechanism to bind withdn
- to bind ascredential
- to bind with in conjunction with dnenv
- to pass to the initial ldap context- Throws:
javax.naming.NamingException
- if a connection cannot be established
-
isConnected
public boolean isConnected()
Returns whether the underlying context has been established.- Specified by:
isConnected
in interfaceConnectionHandler
- Returns:
- whether a connection has been made
-
close
public void close() throws javax.naming.NamingException
Close a connection to an LDAP.- Specified by:
close
in interfaceConnectionHandler
- Throws:
javax.naming.NamingException
- if an LDAP error occurs
-
newInstance
public abstract ConnectionHandler newInstance()
Returns a separate instance of this connection handler with the same underlying ldap configuration.- Specified by:
newInstance
in interfaceConnectionHandler
- Returns:
- connection handler
-
parseLdapUrl
protected java.lang.String[] parseLdapUrl(java.lang.String ldapUrl, ConnectionHandler.ConnectionStrategy strategy)
Parses the supplied ldap url and splits it into separate URLs if it is space delimited.- Parameters:
ldapUrl
- to parsestrategy
- of ordered array to return- Returns:
- array of ldap URLs
-
-