Class TotpCodeVerifier

java.lang.Object
com.irurueta.authserver.authorization.api.web.totp.TotpCodeVerifier

@Component public class TotpCodeVerifier extends Object
Sends a posted code to the use case of its kind (TotpCodeKind): a TOTP code, a recovery code, or the first code of an authenticator app enrolled during the sign-in. The use cases count the failures, lock the second factor after too many and clear the counter on success.
  • Field Details

    • verifyTotpUseCase

      private final VerifyTotpUseCase verifyTotpUseCase
      Use case that verifies a TOTP code.
    • verifyRecoveryCodeUseCase

      private final VerifyRecoveryCodeUseCase verifyRecoveryCodeUseCase
      Use case that verifies (and consumes) a recovery code.
    • confirmTotpAtSignInUseCase

      private final ConfirmTotpAtSignInUseCase confirmTotpAtSignInUseCase
      Use case that confirms an enrolment during the sign-in.
  • Constructor Details

    • TotpCodeVerifier

      public TotpCodeVerifier()
  • Method Details

    • verify

      public boolean verify(TotpAuthenticationToken request, UUID userId, String username)
      Verifies a posted code; for an enrolment, the new recovery codes are handed back through the request.
      Parameters:
      request - the verification request.
      userId - identifier of the user.
      username - name of the user, for the audit log.
      Returns:
      true when the code is accepted.
      Throws:
      SecondFactorLockedException - if the second factor of the user is locked.
      TotpNotEnrolledException - if an enrolment code is posted while no enrolment was started.
      TotpAlreadyEnabledException - if an enrolment code is posted for an app that is already enabled.
    • confirmEnrolment

      private boolean confirmEnrolment(TotpAuthenticationToken request, UUID userId, String username)
      Confirms an enrolment and hands the new recovery codes back through the request.
      Parameters:
      request - the verification request.
      userId - identifier of the user.
      username - name of the user.
      Returns:
      true when the code confirmed the enrolment.