Class VerifyOneTimeCodeUseCase
A code is checked at most OttPolicy.maxAttempts() times: the attempt counter is incremented atomically
before the comparison, and the code is burnt (consumed) after the last wrong attempt or when the counter is already
past the limit. A correct code is accepted once: consuming it must succeed, so of two concurrent submissions of the
same code only one is accepted. Wrong, expired, burnt, already used and mismatching-purpose codes all give the same
OttVerificationResult.failure(). So does a code delivered through a channel the caller does not accept (for a
second factor, the channel that signed the user in, or e-mail for a user with another confirmed second factor): it is
burnt and, as a second factor, counted against the lockout and never audited as a success.
For OttPurpose.SECOND_FACTOR the shared second-factor lockout applies exactly as for TOTP: it is checked
first (a locked user gets OttVerificationResult.locked() and nothing is compared), every failure is
counted, and a success clears the counter and is audited. A OttPurpose.LOGIN code is not counted: the
framework's own authentication events audit it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDetail stored in the audit event of an accepted code.private final CheckSecondFactorLockoutUseCaseUse case that tells whether the second factor is locked (and serializes the attempts of a user).private final ClockSource of the current time.private final FindUserAccountUseCaseUse case that finds the account of the user.private final OneTimeCodeHasherHasher of codes.private final OneTimeCodeRepositoryPort that stores the codes.private final OttPolicyPolicy of the codes.private final RecordSecurityEventUseCaseUse case that records the audit events.private final RegisterSecondFactorFailureUseCaseUse case that counts a failure.private final ResetSecondFactorFailuresUseCaseUse case that clears the failures. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate OttVerificationResultaccept(OneTimeCode active) Consumes a correct code; a code consumed by a concurrent request is refused.private OttVerificationResultcheck(String bindingId, String username, String code, OttPurpose purpose, Set<OttChannel> channels) Checks a code against the active one, counting the attempt.execute(String bindingId, String username, String code, OttPurpose purpose, Set<OttChannel> channels) Verifies a code.private voidrecordSecondFactorOutcome(OttVerificationResult result, UserAccount account) Counts the outcome of a second-factor verification.
-
Field Details
-
AUDIT_DETAIL
Detail stored in the audit event of an accepted code.- See Also:
-
oneTimeCodeRepository
Port that stores the codes. -
oneTimeCodeHasher
Hasher of codes. -
ottPolicy
Policy of the codes. -
findUserAccountUseCase
Use case that finds the account of the user. -
checkSecondFactorLockoutUseCase
Use case that tells whether the second factor is locked (and serializes the attempts of a user). -
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
-
VerifyOneTimeCodeUseCase
public VerifyOneTimeCodeUseCase()
-
-
Method Details
-
execute
public OttVerificationResult execute(String bindingId, String username, String code, OttPurpose purpose, Set<OttChannel> channels) Verifies a code.- Parameters:
bindingId- identifier of the sign-in attempt the code was bound to.username- name of the user.code- the code as typed.purpose- what the code is for.channels- the channels whose codes are accepted; a code of any other channel is a failure.- Returns:
- the outcome.
-
recordSecondFactorOutcome
Counts the outcome of a second-factor verification.- Parameters:
result- the outcome.account- the account of the user.
-
check
private OttVerificationResult check(String bindingId, String username, String code, OttPurpose purpose, Set<OttChannel> channels) Checks a code against the active one, counting the attempt.- Parameters:
bindingId- identifier of the sign-in attempt.username- name of the user.code- the code as typed.purpose- what the code is for.channels- the channels whose codes are accepted.- Returns:
- success when the code is valid and was consumed, failure otherwise.
-
accept
Consumes a correct code; a code consumed by a concurrent request is refused.- Parameters:
active- the stored code.- Returns:
- success when this request consumed it, failure otherwise.
-