Skip to content

Commit

Permalink
Add debug message when an exception is encountered on LDAP retrive call
Browse files Browse the repository at this point in the history
  • Loading branch information
jfleming-ic authored and smiklosovic committed May 24, 2024
1 parent 359fdc5 commit 7535349
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public String searchLdapDN(final String username) throws NamingException
final String filterTemplate = properties.getProperty(LdapAuthenticatorConfiguration.FILTER_TEMPLATE);
final String filter = format(filterTemplate, username);

logger.debug(String.format("User name is %s, going to use filter: %s", username, filter));
logger.debug("User name is {}, going to use filter: {}", username, filter);

String dn = null;

Expand Down Expand Up @@ -133,7 +133,7 @@ public String searchLdapDN(final String username) throws NamingException
+ "User likely does not exist or connection to LDAP server is invalid.", filter, resolvedDns));
}

logger.debug("Returning DN: " + resolvedDns.get(0));
logger.debug("Returning DN: {}", resolvedDns.get(0));

return dn;
} catch (final NamingException ex)
Expand Down Expand Up @@ -186,7 +186,7 @@ public User retrieve(User user) throws LDAPAuthFailedException
{
final String ldapDn = context.searchLdapDN(user.getUsername());

logger.debug(String.format("Resolved LDAP DN: %s", ldapDn));
logger.debug("Resolved LDAP DN: {}", ldapDn);

final Hashtable<String, String> env = getUserEnv(ldapDn,
user.getPassword(),
Expand All @@ -195,7 +195,7 @@ public User retrieve(User user) throws LDAPAuthFailedException

try (final CloseableLdapContext ldapContext = new CloseableLdapContext(new InitialDirContext(env)))
{
logger.debug("Logging to LDAP with {} was ok!", user.toString());
logger.debug("Logging to LDAP with {} was ok!", user);

final User foundUser = new User(user.getUsername(),
hasher.hashPassword(user.getPassword(),
Expand All @@ -211,6 +211,7 @@ public User retrieve(User user) throws LDAPAuthFailedException
}
catch (final Exception ex)
{
logger.debug("Error encountered when authenticating via LDAP {}", ex.getMessage());
throw new LDAPAuthFailedException(ExceptionCode.UNAUTHORIZED, "Not possible to login " + user.getUsername(), ex);
}
}
Expand Down

0 comments on commit 7535349

Please sign in to comment.