在AbstractUserDetailsAuthenticationProvider.class中,我们有一个方法AbstractUserDetailsAuthenticationProvider.authenticate,如果找不到用户名,则抛出BadCredentialsException:
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;
}
}
如果我不想记录错误消息logger.debug(“User'”+ username +“'not found”)该怎么办,因为它是一个安全漏洞(如果用户不小心在用户名中输入密码)然后它被记录下来。)
答案 0 :(得分:1)
通常,当您在生产环境中运行应用程序时,不应将整体日志记录级别运行到debug
,请参阅this answer了解要使用的日志级别。
但是,您可以将此类的日志记录级别配置为比debug
更简洁,例如info
。这样就不会记录User x not found
条目。
要设置各个类的日志级别(取决于实现),请参阅this answer。