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 <aprat...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9aab6046
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9aab6046
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9aab6046

Branch: refs/heads/4.4
Commit: 9aab6046aefebe6bdd9c4e648208f4812f62f7cc
Parents: 234f7e4
Author: Rajani Karuturi <rajanikarut...@gmail.com>
Authored: Tue Apr 22 11:37:31 2014 +0530
Committer: Daan Hoogland <d...@onecht.net>
Committed: Fri Apr 25 21:48:31 2014 +0200

----------------------------------------------------------------------
 .../src/org/apache/cloudstack/ldap/LdapContextFactory.java  | 9 ++++++---
 .../src/org/apache/cloudstack/ldap/LdapManagerImpl.java     | 7 ++++++-
 2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aab6046/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
----------------------------------------------------------------------
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 4f6bb61..491faa3 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<String, String> 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 {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aab6046/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java
----------------------------------------------------------------------
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 6d71f4f..0e3bde8 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);

Reply via email to