你问:
Spring Security:抛出LockedException而不是BadCredentialsException,为什么?
这是因为Spring Security将首先检查该帐户是否存在并有效,然后再检查密码。
更具体:在中完成
AbstractUserDetailsAuthenticationProvider.authenticate。在 非常简短的
说明中,该方法以这种方式工作:
user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);...preAuthenticationChecks.check(user);additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication);...postAuthenticationChecks.check(user);
retrieveUser
-加载用户preAuthenticationChecks.check(user);
-DefaultPreAuthenticationChecks
:检查锁定…additionalAuthenticationChecks
-检查密码postAuthenticationChecks.check(user);
-DefaultPostAuthenticationChecks
检查未过期的凭证
好处是,
preAuthenticationChecks并且
postAuthenticationChecks是接口的引用,
UserDetailsChecker因此您可以更改它们。只需实现自己的两个
UserDetailsChecker,一个用于pre的Null-
Implementation,一个用于检查所有内容的post:
!user.isAccountNonLocked()
!user.isEnabled()
!user.isAccountNonExpired()
!user.isCredentialsNonExpired()



