Class JdbcSecondFactorAttemptRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.mfa.JdbcSecondFactorAttemptRepository
- All Implemented Interfaces:
SecondFactorAttemptRepository
@Repository
public class JdbcSecondFactorAttemptRepository
extends Object
implements SecondFactorAttemptRepository
SecondFactorAttemptRepository over the second_factor_attempts table.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringStatement that creates the clean state of a user unless one exists, so there is always a row to lock.private static final StringQuery returning the state of a user.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.private static final StringQuery returning the state of a user and locking its row until the end of the transaction: a concurrent verification of the same user waits here until the first one commits.private static final StringSingle-statement upsert that counts one failure and sets the lock when the maximum is reached.private static final StringStatement that clears the counter and the lock, keeping the row so later verifications can lock it.private final SecondFactorLockoutRowMapperMaps a row to the state of a user. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReads the state of a user.lockForUpdate(UUID userId) Reads and locks the state of a user, in the caller's transaction (without one, the lock is released as soon as the query ends).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.
-
Field Details
-
FIND_ATTEMPTS
Query returning the state of a user.- See Also:
-
ENSURE_ATTEMPTS
Statement that creates the clean state of a user unless one exists, so there is always a row to lock.- See Also:
-
LOCK_ATTEMPTS
Query returning the state of a user and locking its row until the end of the transaction: a concurrent verification of the same user waits here until the first one commits.- See Also:
-
RESET_ATTEMPTS
Statement that clears the counter and the lock, keeping the row so later verifications can lock it.- See Also:
-
RECORD_FAILURE
Single-statement upsert that counts one failure and sets the lock when the maximum is reached. A lock that has already ended restarts the counter at one. Concurrent failures serialize on the row, so none is lost.- See Also:
-
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements. -
secondFactorLockoutRowMapper
Maps a row to the state of a user.
-
-
Constructor Details
-
JdbcSecondFactorAttemptRepository
public JdbcSecondFactorAttemptRepository()
-
-
Method Details
-
find
Description copied from interface:SecondFactorAttemptRepositoryReads the state of a user.- Specified by:
findin interfaceSecondFactorAttemptRepository- Parameters:
userId- identifier of the user.- Returns:
- the state;
SecondFactorLockout.none()when nothing was recorded.
-
lockForUpdate
Reads and locks the state of a user, in the caller's transaction (without one, the lock is released as soon as the query ends).- Specified by:
lockForUpdatein interfaceSecondFactorAttemptRepository- Parameters:
userId- identifier of the user.- Returns:
- the state.
-
recordFailure
public SecondFactorLockout recordFailure(UUID userId, int maxAttempts, Duration lockout, Instant now) Description copied from interface:SecondFactorAttemptRepositoryRecords one failed attempt and, when the counter reaches the maximum, locks the second factor.- Specified by:
recordFailurein interfaceSecondFactorAttemptRepository- 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
Description copied from interface:SecondFactorAttemptRepositoryClears the counter and any lock, after a successful verification.- Specified by:
resetin interfaceSecondFactorAttemptRepository- Parameters:
userId- identifier of the user.
-