Author: tolusha
Date: 2010-08-19 10:26:58 -0400 (Thu, 19 Aug 2010)
New Revision: 2952
Modified:
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java
Log:
EXOJCR-909: close LDAP context in LDAPServiceImpl.authenticate() method
Modified:
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java 2010-08-19
14:20:08 UTC (rev 2951)
+++
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java 2010-08-19
14:26:58 UTC (rev 2952)
@@ -132,15 +132,7 @@
{
// Just close since we are not pooling anything by self.
// Override this method if need other behavior.
- try
- {
- if (ctx != null)
- ctx.close();
- }
- catch (NamingException e)
- {
- LOG.warn("Exception occur when try close LDAP context. ", e);
- }
+ closeContext(ctx);
}
/**
@@ -164,17 +156,22 @@
props.put(Context.SECURITY_PRINCIPAL, userDN);
props.put(Context.SECURITY_CREDENTIALS, password);
props.put("com.sun.jndi.ldap.connect.pool", "false");
+
+ LdapContext ctx = null;
try
{
- new InitialLdapContext(props, null);
+ ctx = new InitialLdapContext(props, null);
return true;
}
catch (NamingException e)
{
- if (LOG.isDebugEnabled())
- e.printStackTrace();
+ LOG.debug("Exception during initilization LDAP context", e);
return false;
}
+ finally
+ {
+ closeContext(ctx);
+ }
}
/**
@@ -341,4 +338,25 @@
return DEFAULT_SERVER;
}
+ /**
+ * Closes LDAP context and shows warning if exception occurred.
+ *
+ * @param ctx
+ * LDAP context
+ */
+ private void closeContext(Context ctx)
+ {
+ try
+ {
+ if (ctx != null)
+ {
+ ctx.close();
+ }
+ }
+ catch (NamingException e)
+ {
+ LOG.warn("Exception occurred when tried to close context", e);
+ }
+ }
+
}