Class VerifyRecoveryCodeUseCase

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

@Service @Transactional public class VerifyRecoveryCodeUseCase extends Object
Use case that accepts a recovery code as a second factor. A code works once. Every stored code is checked, with no early exit, so the time taken does not reveal which one matched; failures count towards the lockout. A user without a confirmed second factor has no usable recovery code: the attempt fails and is counted.
  • Field Details

    • recoveryCodeRepository

      private final RecoveryCodeRepository recoveryCodeRepository
      Port that stores the recovery codes.
    • passwordHasher

      private final PasswordHasher passwordHasher
      Port that hashes the codes like passwords.
    • recoveryCodes

      private final RecoveryCodes recoveryCodes
      Normalizer of typed codes.
    • hasConfirmedSecondFactorUseCase

      private final HasConfirmedSecondFactorUseCase hasConfirmedSecondFactorUseCase
      Use case that tells whether the user has confirmed a second factor.
    • 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

    • VerifyRecoveryCodeUseCase

      public VerifyRecoveryCodeUseCase()
  • Method Details

    • execute

      public boolean execute(UUID userId, String username, String code)
      Verifies and consumes a recovery 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 was valid (and is now used up); false when it was not, or the user has no confirmed second factor.
      Throws:
      SecondFactorLockedException - if the second factor of the user is locked.