I’ve subclassed org.springframework.security.core.userdetails.User and in my constructor I call:
Super (String username,
String password,
boolean enabled,
boolean accountNonExpired,
boolean credentialsNonExpired,
boolean accountNonLocked,
GrantedAuthority[] authorities)
I then use ${SPRING_SECURITY_LAST_EXCEPTION.message} to display the result when login fails.
The problem I have is that if I set accountNotLocked to false then the account locked error message is displayed and this happens whether or not the password is correct. I would far prefer it if spring validated credentials first and then enabled, accountNonExpired, credentialsNonExpired and accountNonLocked flags. This way a user would only be notified that their account was locked if they got the credentials right.
Is there a way to force spring to do this?
I assume you’re using most popular
DaoAuthenticationProviderand that the problem is inUserDetailsCheckerdefault implementations in this class. That said, moving all checks afterDaoAuthenticationProvider.additionalAuthenticationChecksshould be enough to solve your problem. Try following config:where
com.example.NullUserDetailsCheckeris null object pattern implementation ofUserDetailsChecker(has void check method which does nothing).