Skip to content

Commit fe305a5

Browse files
karuturiAbhinandan Prateek
authored andcommitted
improved ldap logging. added stacktrace in debug level incase of exceptions.
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
1 parent a289330 commit fe305a5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ private DirContext createInitialDirContext(final String principal,
6262
private DirContext createInitialDirContext(final String principal,
6363
final String password, final String providerUrl,
6464
final boolean isSystemContext) throws NamingException {
65-
return new InitialDirContext(getEnvironment(principal, password,
66-
providerUrl, isSystemContext));
65+
Hashtable<String, String> environment = getEnvironment(principal, password, providerUrl, isSystemContext);
66+
s_logger.debug("initializing ldap with provider url: "+ environment.get(Context.PROVIDER_URL));
67+
return new InitialDirContext(environment);
6768
}
6869

6970
public DirContext createUserContext(final String principal,

plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public LdapConfigurationResponse addConfiguration(final String hostname, final i
7272
s_logger.info("Added new ldap server with hostname: " + hostname);
7373
return new LdapConfigurationResponse(hostname, port);
7474
} catch (final NamingException e) {
75+
s_logger.debug("NamingException while doing an LDAP bind", e);
7576
throw new InvalidParameterValueException("Unable to bind to the given LDAP server");
7677
}
7778
} else {
@@ -89,6 +90,7 @@ public boolean canAuthenticate(final String username, final String password) {
8990
closeContext(context);
9091
return true;
9192
} catch (final NamingException e) {
93+
s_logger.debug("NamingException: while doing an LDAP bind for user "+" "+username, e);
9294
s_logger.info("Failed to authenticate user: " + username + ". incorrect password.");
9395
return false;
9496
}
@@ -100,7 +102,7 @@ private void closeContext(final DirContext context) {
100102
context.close();
101103
}
102104
} catch (final NamingException e) {
103-
s_logger.warn(e.getMessage());
105+
s_logger.warn(e.getMessage(),e);
104106
}
105107
}
106108

@@ -174,6 +176,7 @@ public List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException {
174176
context = _ldapContextFactory.createBindContext();
175177
return _ldapUserManager.getUsers(context);
176178
} catch (final NamingException e) {
179+
s_logger.debug("ldap NamingException: ",e);
177180
throw new NoLdapUserMatchingQueryException("*");
178181
} finally {
179182
closeContext(context);
@@ -187,6 +190,7 @@ public List<LdapUser> getUsersInGroup(String groupName) throws NoLdapUserMatchin
187190
context = _ldapContextFactory.createBindContext();
188191
return _ldapUserManager.getUsersInGroup(groupName, context);
189192
} catch (final NamingException e) {
193+
s_logger.debug("ldap NamingException: ",e);
190194
throw new NoLdapUserMatchingQueryException("groupName=" + groupName);
191195
} finally {
192196
closeContext(context);
@@ -214,6 +218,7 @@ public List<LdapUser> searchUsers(final String username) throws NoLdapUserMatchi
214218
final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username);
215219
return _ldapUserManager.getUsers("*" + escapedUsername + "*", context);
216220
} catch (final NamingException e) {
221+
s_logger.debug("ldap NamingException: ",e);
217222
throw new NoLdapUserMatchingQueryException(username);
218223
} finally {
219224
closeContext(context);

0 commit comments

Comments
 (0)