Connection timed out - jndi ldap

M

markpittsnh

My application creates the initialdircontext from the init method of
the class. This is performed only once upon system startup. Every user
that authenticates through ldap uses this preexisting DirContext. For
some time the authentication works. After some time, I begin to
experiencing connection timeouts when the call to.....

NamingEnumeration results = ctx.search(ldapInfo.getSearchBaseDN(),
searchTerm, constraints);

.....occurs. Refer to snippet below. Stack trace also included.

Thanks and regards,
Mark

public class AuthLDAPSource {
....
....
private static DirContext ctx = null;

public static void init(LDAPStoreConfiguration ldap_config) throws
InitException {
ldapInfo = ldap_config;

// Environment to set up the security context
Hashtable env = new Hashtable();
if(ldapInfo.useSSL()) { // Connect with SSL
// JSSE will be bundled with J2SE 1.4, so won't need this
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
env.put(Context.SECURITY_PROTOCOL, "ssl");
}
// Read the service provider
env.put(Context.INITIAL_CONTEXT_FACTORY,
ldapInfo.getContextProvider());
// the URL of the LDAP Server
env.put(Context.PROVIDER_URL, "ldap://" + ldapInfo.getHost() + ":" +
ldapInfo.getPort());
cat.info("Initializing LDAP with URL: "+env.get(Context.PROVIDER_URL));
EmployAuthInformation employAuth = ldapInfo.getEmployAuthInformation();

// Most LDAP servers allow anonymous access. However, in the case where
they don't, Employ!
// needs to log in with an account that exists on the LDAP.
if(employAuth != null) {
env.put(Context.SECURITY_AUTHENTICATION, "simple");
System.out.println(employAuth.getAuthDistinguishedName());
env.put(Context.SECURITY_PRINCIPAL,
employAuth.getAuthDistinguishedName());
env.put(Context.SECURITY_CREDENTIALS, employAuth.getAuthPassword());
cat.info("Initializing LDAP with DN:
"+env.get(Context.SECURITY_PRINCIPAL));
}else{
// log in anonymously
env.put(Context.SECURITY_AUTHENTICATION, "none");
cat.info("Initializing LDAP with anonymous access.");
}
try {
// Connect
ctx = new InitialDirContext(env);
}
catch(...
....
....
}


public static void authenticate(String user_id, String password, String
hire_date) throws InvalidCredentials,
NoSuchUser, StoreConnectionException, LDAPSourceException {
try {

SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
// Construct search term
String searchTerm = ldapInfo.getSearchAttributeName() + "=" + user_id;
if(cat.isDebugEnabled()) {
cat.debug("LDAP Searching for: "+searchTerm+" at base DN:
"+ldapInfo.getSearchBaseDN());
}
// Context Search for user based off of Search Base
EXCEPTION Thrown here >>>>>> NamingEnumeration results =
ctx.search(ldapInfo.getSearchBaseDN(), searchTerm, constraints);
.....
....
....

javax.naming.CommunicationException: Connection timed out [Root
exception is java.net.SocketException: Connection timed out]; remaining
name 'o=BMGC'
289 at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1964)
291 at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1809)
293 at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1734)
295 at
com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:368)
298 at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:328)
300 at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:313)
302 at
javax.naming.directory.InitialDirContext.search(InitialDirContext.java:238)
304 at
com.deploy.authentication.source.AuthLDAPSource.authenticate(AuthLDAPSource.java:275)
306 at
com.deploy.authentication.Authenticator.authenticate(Authenticator.java:180)
308 at com.azetra.wrappers.authenticate.authuser(authenticate.java:33)
310 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
313 at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
315 at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
317 at java.lang.reflect.Method.invoke(Method.java:324)
....
....
....
494 INFO XCT.Stdout (LogStream.java:36) - Caused by:
java.net.SocketException: Connection timed out
496 at java.net.SocketInputStream.socketRead0(Native Method)
498 at java.net.SocketInputStream.read(SocketInputStream.java:129)
500 at com.sun.net.ssl.internal.ssl.InputRecord.a(DashoA12275)
503 at com.sun.net.ssl.internal.ssl.InputRecord.read(DashoA12275)
505 at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA12275)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top