1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Use UsernameNotFoundException Factory

Issue gh-17179
This commit is contained in:
Josh Cummings
2025-05-28 14:13:02 -06:00
parent da2d9aa868
commit 215547f8c8
6 changed files with 6 additions and 7 deletions
@@ -93,7 +93,7 @@ public final class PasswordComparisonAuthenticator extends AbstractLdapAuthentic
}
}
if (user == null) {
throw new UsernameNotFoundException("User not found: " + username);
throw UsernameNotFoundException.fromUsername(username);
}
if (logger.isTraceEnabled()) {
logger.trace(LogMessage.format("Comparing password attribute '%s' for user '%s'",
@@ -307,8 +307,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
throw ex;
}
// If we found no results, then the username/password did not match
UsernameNotFoundException userNameNotFoundException = new UsernameNotFoundException(
"User " + username + " not found in directory.", ex);
UsernameNotFoundException userNameNotFoundException = UsernameNotFoundException.fromUsername(username, ex);
throw badCredentials(userNameNotFoundException);
}
}
@@ -104,7 +104,7 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
}
catch (IncorrectResultSizeDataAccessException ex) {
if (ex.getActualSize() == 0) {
throw new UsernameNotFoundException("User " + username + " not found in directory.");
throw UsernameNotFoundException.fromUsername(username);
}
// Search should never return multiple results if properly configured
throw ex;
@@ -154,7 +154,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
return new DirContextAdapter(attrs, LdapUtils.getFullDn(dn, ctx));
}
catch (NameNotFoundException ex) {
throw new UsernameNotFoundException("User " + username + " not found", ex);
throw UsernameNotFoundException.fromUsername(username, ex);
}
});
}