From a92610d2772f7f59a099de9f1a0af49df9920d75 Mon Sep 17 00:00:00 2001 From: Rajani Karuturi Date: Tue, 22 Apr 2014 11:37:31 +0530 Subject: [PATCH] improved ldap logging. added stacktrace in debug level incase of exceptions. Conflicts: plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java Signed-off-by: Abhinandan Prateek --- .../org/apache/cloudstack/ldap/LdapContextFactory.java | 9 ++++++--- .../src/org/apache/cloudstack/ldap/LdapManagerImpl.java | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java index 4f6bb618c26..491faa348c6 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java @@ -53,9 +53,12 @@ public class LdapContextFactory { return createInitialDirContext(principal, password, null, isSystemContext); } - private DirContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext) - throws NamingException { - return new InitialDirContext(getEnvironment(principal, password, providerUrl, isSystemContext)); + private DirContext createInitialDirContext(final String principal, + final String password, final String providerUrl, + final boolean isSystemContext) throws NamingException { + Hashtable environment = getEnvironment(principal, password, providerUrl, isSystemContext); + s_logger.debug("initializing ldap with provider url: "+ environment.get(Context.PROVIDER_URL)); + return new InitialDirContext(environment); } public DirContext createUserContext(final String principal, final String password) throws NamingException { diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java index 6d71f4f17dd..0e3bde840ff 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java @@ -81,6 +81,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { s_logger.info("Added new ldap server with hostname: " + hostname); return new LdapConfigurationResponse(hostname, port); } catch (final NamingException e) { + s_logger.debug("NamingException while doing an LDAP bind", e); throw new InvalidParameterValueException("Unable to bind to the given LDAP server"); } } else { @@ -98,6 +99,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { closeContext(context); return true; } catch (final NamingException e) { + s_logger.debug("NamingException: while doing an LDAP bind for user "+" "+username, e); s_logger.info("Failed to authenticate user: " + username + ". incorrect password."); return false; } @@ -109,7 +111,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { context.close(); } } catch (final NamingException e) { - s_logger.warn(e.getMessage()); + s_logger.warn(e.getMessage(),e); } } @@ -183,6 +185,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { context = _ldapContextFactory.createBindContext(); return _ldapUserManager.getUsers(context); } catch (final NamingException e) { + s_logger.debug("ldap NamingException: ",e); throw new NoLdapUserMatchingQueryException("*"); } finally { closeContext(context); @@ -196,6 +199,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { context = _ldapContextFactory.createBindContext(); return _ldapUserManager.getUsersInGroup(groupName, context); } catch (final NamingException e) { + s_logger.debug("ldap NamingException: ",e); throw new NoLdapUserMatchingQueryException("groupName=" + groupName); } finally { closeContext(context); @@ -223,6 +227,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username); return _ldapUserManager.getUsers("*" + escapedUsername + "*", context); } catch (final NamingException e) { + s_logger.debug("ldap NamingException: ",e); throw new NoLdapUserMatchingQueryException(username); } finally { closeContext(context);