mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-30 16:52:13 +00:00
Use UsernameNotFoundException Factory
Issue gh-17179
This commit is contained in:
parent
da2d9aa868
commit
215547f8c8
@ -164,7 +164,7 @@ public class InMemoryUserDetailsManager implements UserDetailsManager, UserDetai
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
UserDetails user = this.users.get(username.toLowerCase(Locale.ROOT));
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException("user '" + username + "' not found");
|
||||
throw UsernameNotFoundException.fromUsername(username);
|
||||
}
|
||||
if (user instanceof CredentialsContainer) {
|
||||
return user;
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class ReactivePreAuthenticatedAuthenticationManager implements ReactiveAu
|
||||
.filter(this::supports)
|
||||
.map(Authentication::getName)
|
||||
.flatMap(this.userDetailsService::findByUsername)
|
||||
.switchIfEmpty(Mono.error(() -> new UsernameNotFoundException("User not found")))
|
||||
.switchIfEmpty(Mono.error(() -> UsernameNotFoundException.fromUsername(authentication.getName())))
|
||||
.doOnNext(this.userDetailsChecker::check)
|
||||
.map((userDetails) -> {
|
||||
PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(userDetails,
|
||||
|
Loading…
x
Reference in New Issue
Block a user