java.lang.Object
com.irurueta.authserver.authorization.application.totp.VerifyTotpUseCase

@Service @Transactional public class VerifyTotpUseCase extends Object
Use case that verifies a TOTP code presented as a second factor: ±1 step window, no replay of a step already used, lockout after repeated failures, and an audit event either way.
  • Field Details

    • totpCredentialRepository

      private final TotpCredentialRepository totpCredentialRepository
      Port that stores the TOTP credentials.
    • totpSecretCipher

      private final TotpSecretCipher totpSecretCipher
      Port that decrypts the secrets.
    • totpAlgorithm

      private final TotpAlgorithm totpAlgorithm
      The TOTP algorithm.
    • checkSecondFactorLockoutUseCase

      private final CheckSecondFactorLockoutUseCase checkSecondFactorLockoutUseCase
      Use case that tells whether the second factor is locked.
    • registerSecondFactorFailureUseCase

      private final RegisterSecondFactorFailureUseCase registerSecondFactorFailureUseCase
      Use case that counts a failure.
    • resetSecondFactorFailuresUseCase

      private final ResetSecondFactorFailuresUseCase resetSecondFactorFailuresUseCase
      Use case that clears the failures.
    • recordSecurityEventUseCase

      private final RecordSecurityEventUseCase recordSecurityEventUseCase
      Use case that records the audit events.
    • clock

      private final Clock clock
      Source of the current time.
  • Constructor Details

    • VerifyTotpUseCase

      public VerifyTotpUseCase()
  • Method Details

    • execute

      public boolean execute(UUID userId, String username, String code)
      Verifies a code.
      Parameters:
      userId - identifier of the user.
      username - name of the user, for the audit log.
      code - the code as typed.
      Returns:
      true if the code is valid and fresh.
      Throws:
      SecondFactorLockedException - if the second factor of the user is locked.