Class VerifyRecoveryCodeUseCase
java.lang.Object
com.irurueta.authserver.authorization.application.totp.VerifyRecoveryCodeUseCase
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final CheckSecondFactorLockoutUseCaseUse case that tells whether the second factor is locked.private final ClockSource of the current time.private final HasConfirmedSecondFactorUseCaseUse case that tells whether the user has confirmed a second factor.private final PasswordHasherPort that hashes the codes like passwords.private final RecordSecurityEventUseCaseUse case that records the audit events.private final RecoveryCodeRepositoryPort that stores the recovery codes.private final RecoveryCodesNormalizer of typed codes.private final RegisterSecondFactorFailureUseCaseUse case that counts a failure.private final ResetSecondFactorFailuresUseCaseUse case that clears the failures. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
recoveryCodeRepository
Port that stores the recovery codes. -
passwordHasher
Port that hashes the codes like passwords. -
recoveryCodes
Normalizer of typed codes. -
hasConfirmedSecondFactorUseCase
Use case that tells whether the user has confirmed a second factor. -
checkSecondFactorLockoutUseCase
Use case that tells whether the second factor is locked. -
registerSecondFactorFailureUseCase
Use case that counts a failure. -
resetSecondFactorFailuresUseCase
Use case that clears the failures. -
recordSecurityEventUseCase
Use case that records the audit events. -
clock
Source of the current time.
-
-
Constructor Details
-
VerifyRecoveryCodeUseCase
public VerifyRecoveryCodeUseCase()
-
-
Method Details
-
execute
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:
trueif the code was valid (and is now used up);falsewhen it was not, or the user has no confirmed second factor.- Throws:
SecondFactorLockedException- if the second factor of the user is locked.
-