In AbstractUserDetailsAuthenticationProvider.class we have a method AbstractUserDetailsAuthenticationProvider.authenticate, a BadCredentialsException is thrown if the username is not found:
try {
user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);
} catch (UsernameNotFoundException notFound) {
***logger.debug("User '" + username + "' not found");***
if (hideUserNotFoundExceptions) {
throw new BadCredentialsException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
} else {
throw notFound;
}
}
What to do in case I don't want to log the error message logger.debug("User '" + username + "' not found") as it is a security vulnerability (if a user accidentally enters password in username then it gets logged).