Interface SecondFactorAttemptRepository
public interface SecondFactorAttemptRepository
Port that keeps the failed second-factor attempts of each user, so that a lockout survives restarts and is shared by
every instance of the server.
-
Method Summary
Modifier and TypeMethodDescriptionReads the state of a user.lockForUpdate(UUID userId) Reads the state of a user and locks it until the end of the current transaction, creating a clean state first when nothing was recorded, so that concurrent verifications of the same user's second factor run one after the other instead of all passing the lockout check before any of their failures is counted.recordFailure(UUID userId, int maxAttempts, Duration lockout, Instant now) Records one failed attempt and, when the counter reaches the maximum, locks the second factor.voidClears the counter and any lock, after a successful verification.
-
Method Details
-
find
Reads the state of a user.- Parameters:
userId- identifier of the user.- Returns:
- the state;
SecondFactorLockout.none()when nothing was recorded.
-
lockForUpdate
Reads the state of a user and locks it until the end of the current transaction, creating a clean state first when nothing was recorded, so that concurrent verifications of the same user's second factor run one after the other instead of all passing the lockout check before any of their failures is counted.- Parameters:
userId- identifier of the user.- Returns:
- the state;
SecondFactorLockout.none()when nothing was recorded.
-
recordFailure
Records one failed attempt and, when the counter reaches the maximum, locks the second factor.- Parameters:
userId- identifier of the user.maxAttempts- consecutive failures that trigger the lock.lockout- how long the lock lasts.now- current instant.- Returns:
- the state after the failure.
-
reset
Clears the counter and any lock, after a successful verification.- Parameters:
userId- identifier of the user.
-