You asked:
Spring Security: LockedException thrown instead of BadCredentialsException thrown, why?
This is because spring protection will first verify that the account exists and is valid, and after that it verifies the password.
More specific: this is done in AbstractUserDetailsAuthenticationProvider.authenticate . In a very brief description, the method works as follows:
user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication); ... preAuthenticationChecks.check(user); additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication); ... postAuthenticationChecks.check(user);
retrieveUser - load userpreAuthenticationChecks.check(user); - DefaultPreAuthenticationChecks : check blocked ...additionalAuthenticationChecks - verifies passwordpostAuthenticationChecks.check(user); - DefaultPostAuthenticationChecks check expired credentials
It's good that preAuthenticationChecks and postAuthenticationChecks are links to the UserDetailsChecker interface, so you can change them. Just implement your own two UserDetailsChecker , one Null-Implementation for pre and one for the message, which checks everything:
!user.isAccountNonLocked()!user.isEnabled()!user.isAccountNonExpired()!user.isCredentialsNonExpired()
Ralph source share