Class PasswordAuthenticationConfiguration
UserDetailsService bean, to close a user enumeration.
The provider Spring Security builds checks the account status (locked, disabled, expired) before the
password, so a wrong password for, say, a disabled account answers "disabled": the page would reveal that the
account exists to anyone who types its username. This provider checks nothing before the password and the account
status after it (AccountStatusUserDetailsChecker), so a wrong password always gets the same generic answer,
known user or not, and a status message only appears to whoever proved they know the password.
Everything else is kept as the auto-built provider had it: the PasswordEncoder, the
UserDetailsPasswordService (which stores the stronger hash after a sign-in with an outdated encoding), a
CompromisedPasswordChecker when one bean of that type exists, and the hiding of unknown users behind a bad
credentials error. Being the only AuthenticationProvider bean, it is the one the global authentication
manager uses.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final org.springframework.security.core.userdetails.UserDetailsCheckerChecks nothing before the password: the account status is only checked, and reported, after it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.authentication.dao.DaoAuthenticationProviderpasswordAuthenticationProvider(org.springframework.security.core.userdetails.UserDetailsService userDetailsService, org.springframework.security.core.userdetails.UserDetailsPasswordService userDetailsPasswordService, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, org.springframework.beans.factory.ObjectProvider<org.springframework.security.authentication.password.CompromisedPasswordChecker> compromisedPasswordChecker) Creates the authentication provider of the username and password sign-in.
-
Field Details
-
NO_PRE_AUTHENTICATION_CHECKS
static final org.springframework.security.core.userdetails.UserDetailsChecker NO_PRE_AUTHENTICATION_CHECKSChecks nothing before the password: the account status is only checked, and reported, after it.
-
-
Constructor Details
-
PasswordAuthenticationConfiguration
public PasswordAuthenticationConfiguration()
-
-
Method Details
-
passwordAuthenticationProvider
@Bean public org.springframework.security.authentication.dao.DaoAuthenticationProvider passwordAuthenticationProvider(org.springframework.security.core.userdetails.UserDetailsService userDetailsService, org.springframework.security.core.userdetails.UserDetailsPasswordService userDetailsPasswordService, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, org.springframework.beans.factory.ObjectProvider<org.springframework.security.authentication.password.CompromisedPasswordChecker> compromisedPasswordChecker) Creates the authentication provider of the username and password sign-in.- Parameters:
userDetailsService- loads the account by username.userDetailsPasswordService- stores the upgraded hash after a sign-in with an outdated encoding.passwordEncoder- verifies the password, and tells when its hash needs upgrading.compromisedPasswordChecker- the compromised-password checker of Spring Security, when one is declared.- Returns:
- the provider, which checks the account status only after a correct password.
-