Class TotpAuthenticationProvider

java.lang.Object
com.irurueta.authserver.authorization.api.web.totp.TotpAuthenticationProvider
All Implemented Interfaces:
org.springframework.security.authentication.AuthenticationProvider

public class TotpAuthenticationProvider extends Object implements org.springframework.security.authentication.AuthenticationProvider
Verifies a TOTP code or a recovery code for the signed-in user, or the first code of an authenticator app being enrolled during the sign-in, which confirms it, through the TotpCodeVerifier. The use cases count the failures, lock the second factor after too many and clear the counter on success; a locked second factor is rejected even for a correct code. A correct code answers with the authentication the user already holds plus the TOTP factor authority; an enrolment also hands the new recovery codes back through the request token.
  • Field Details

    • totpCodeVerifier

      private final TotpCodeVerifier totpCodeVerifier
      Sends the code to the use case of its kind.
    • userResolver

      private final SecondFactorUserResolver userResolver
      Resolves the identifier of the account of the signed-in user.
    • factorGrantor

      private final FactorGrantor factorGrantor
      Adds the factor authority to an authentication.
  • Constructor Details

    • TotpAuthenticationProvider

      public TotpAuthenticationProvider()
  • Method Details

    • authenticate

      public org.springframework.security.core.Authentication authenticate(org.springframework.security.core.Authentication authentication) throws org.springframework.security.core.AuthenticationException
      Verifies the code.
      Specified by:
      authenticate in interface org.springframework.security.authentication.AuthenticationProvider
      Parameters:
      authentication - the TotpAuthenticationToken to verify.
      Returns:
      the authentication the user already holds with the TOTP factor added.
      Throws:
      org.springframework.security.core.AuthenticationException - if the code is wrong, the second factor is locked or the account is unknown.
    • supports

      public boolean supports(Class<?> authentication)
      Tells which requests this provider verifies.
      Specified by:
      supports in interface org.springframework.security.authentication.AuthenticationProvider
      Parameters:
      authentication - the type of the request.
      Returns:
      true for a TotpAuthenticationToken.