Skip to content

Commit 9aab604

Browse files
karuturiDaanHoogland
authored andcommitted
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 <aprateek@apache.org>
1 parent 234f7e4 commit 9aab604

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ private DirContext createInitialDirContext(final String principal, final String
5353
return createInitialDirContext(principal, password, null, isSystemContext);
5454
}
5555

56-
private DirContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext)
57-
throws NamingException {
58-
return new InitialDirContext(getEnvironment(principal, password, providerUrl, isSystemContext));
56+
private DirContext createInitialDirContext(final String principal,
57+
final String password, final String providerUrl,
58+
final boolean isSystemContext) throws NamingException {
59+
Hashtable<String, String> environment = getEnvironment(principal, password, providerUrl, isSystemContext);
60+
s_logger.debug("initializing ldap with provider url: "+ environment.get(Context.PROVIDER_URL));
61+
return new InitialDirContext(environment);
5962
}
6063

6164
public DirContext createUserContext(final String principal, final String password) throws NamingException {

‎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
@@ -81,6 +81,7 @@ public LdapConfigurationResponse addConfiguration(final String hostname, final i
8181
s_logger.info("Added new ldap server with hostname: " + hostname);
8282
return new LdapConfigurationResponse(hostname, port);
8383
} catch (final NamingException e) {
84+
s_logger.debug("NamingException while doing an LDAP bind", e);
8485
throw new InvalidParameterValueException("Unable to bind to the given LDAP server");
8586
}
8687
} else {
@@ -98,6 +99,7 @@ public boolean canAuthenticate(final String username, final String password) {
9899
closeContext(context);
99100
return true;
100101
} catch (final NamingException e) {
102+
s_logger.debug("NamingException: while doing an LDAP bind for user "+" "+username, e);
101103
s_logger.info("Failed to authenticate user: " + username + ". incorrect password.");
102104
return false;
103105
}
@@ -109,7 +111,7 @@ private void closeContext(final DirContext context) {
109111
context.close();
110112
}
111113
} catch (final NamingException e) {
112-
s_logger.warn(e.getMessage());
114+
s_logger.warn(e.getMessage(),e);
113115
}
114116
}
115117

@@ -183,6 +185,7 @@ public List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException {
183185
context = _ldapContextFactory.createBindContext();
184186
return _ldapUserManager.getUsers(context);
185187
} catch (final NamingException e) {
188+
s_logger.debug("ldap NamingException: ",e);
186189
throw new NoLdapUserMatchingQueryException("*");
187190
} finally {
188191
closeContext(context);
@@ -196,6 +199,7 @@ public List<LdapUser> getUsersInGroup(String groupName) throws NoLdapUserMatchin
196199
context = _ldapContextFactory.createBindContext();
197200
return _ldapUserManager.getUsersInGroup(groupName, context);
198201
} catch (final NamingException e) {
202+
s_logger.debug("ldap NamingException: ",e);
199203
throw new NoLdapUserMatchingQueryException("groupName=" + groupName);
200204
} finally {
201205
closeContext(context);
@@ -223,6 +227,7 @@ public List<LdapUser> searchUsers(final String username) throws NoLdapUserMatchi
223227
final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username);
224228
return _ldapUserManager.getUsers("*" + escapedUsername + "*", context);
225229
} catch (final NamingException e) {
230+
s_logger.debug("ldap NamingException: ",e);
226231
throw new NoLdapUserMatchingQueryException(username);
227232
} finally {
228233
closeContext(context);

0 commit comments

Comments
 (0)