Class PasswordAuthenticationConfiguration

java.lang.Object
com.irurueta.authserver.authorization.api.web.password.PasswordAuthenticationConfiguration

@Configuration(proxyBeanMethods=false) public class PasswordAuthenticationConfiguration extends Object
Declares the authentication provider of the password-based sign-in, instead of the one Spring Security builds from the 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

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final org.springframework.security.core.userdetails.UserDetailsChecker
    Checks nothing before the password: the account status is only checked, and reported, after it.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NO_PRE_AUTHENTICATION_CHECKS

      static final org.springframework.security.core.userdetails.UserDetailsChecker NO_PRE_AUTHENTICATION_CHECKS
      Checks 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.