|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.cafesoft.cams.auth.login.module.TimeoutLDAPSocketFactory
public class TimeoutLDAPSocketFactory
TimeoutLDAPSocketFactory implements an LDAPSocketFactory that
provides connection timeout functionality. This is useful for Cams
LDAP-based LoginModules when the default LDAPSocketFactory takes too long
to fail when attempting to connect with an LDAP server, causing
Cams agents to timeout while waiting for an authentication request.
When multiple LoginModules are stacked, it may be desireable to enable
authentication success based on the results from other LoginModules.
This class essentially implements a way to interrupt an attempted
connection to an LDAP server, which can take nearly 1 minute to fail in
cases where the LDAP server host is unavailable due to a network outage.
This class will delegate to the specified LDAPSocketFactory if one is provided or will create a Socket directly if necessary. Because a new Thread is started to wait for the actual connection timeout, it may continue running well after the enclosing LoginModule has exited. The Thread will eventually stop and cleanup allocated resources.
The following example code shows how this class may be used:
import com.cafesoft.cams.auth.login.module.TimeoutLDAPSocketFactory
...
// Create an LDAPConnection to see if default LDAPSocketFactory is set
LDAPConnection connection = new LDAPConnection();
// Get the default LDAPSocketFactory (this may be null)
LDAPSocketFactory defaultSocketFactory = connection.getSocketFactory();
// Create an LDAPSocketFactory that will timeout on connection
// (The timeout is set to 500 milliseconds for this example)
LDAPSocketFactory timeoutSocketFactory =
new TimeoutLDAPSocketFactory(defaultSocketFactory, 500L);
// Now create a new LDAPConnection that uses the new factory
connection = null;
connection = new LDAPConnection(timeoutSocketFactory);
// Attempt to connect with the LDAP server
connection.connect();
LDAPSocketFactory| Constructor Summary | |
|---|---|
TimeoutLDAPSocketFactory(com.novell.ldap.LDAPSocketFactory factory,
long timeout)
Create a new TimeoutLDAPSocketFactory. |
|
| Method Summary | |
|---|---|
Socket |
createSocket(String host,
int port)
Create a new Socket to an LDAP server. |
void |
run()
Attempt to connect with the LDAP server |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TimeoutLDAPSocketFactory(com.novell.ldap.LDAPSocketFactory factory,
long timeout)
factory - the real LDAPSocketFactory to which socket creation
will be delegated. If null, then a standard Socket will be created.timeout - the number of milliseconds to wait for connection
before timing out.| Method Detail |
|---|
public Socket createSocket(String host,
int port)
throws IOException,
UnknownHostException
createSocket in interface com.novell.ldap.LDAPSocketFactoryhost - the host name or IP addressport - the TCP port
IOException - if unable to connect to the server at the
specified host/port within the configured timeout.
UnknownHostException - if the host is unknown.public void run()
run in interface Runnable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||