Class JdbcRecoveryCodeRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.totp.JdbcRecoveryCodeRepository
- All Implemented Interfaces:
RecoveryCodeRepository
@Repository
public class JdbcRecoveryCodeRepository
extends Object
implements RecoveryCodeRepository
RecoveryCodeRepository over the recovery_codes table. It opens no transaction: replacing the codes
of a user runs in the caller's.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringStatement deleting every code of a user.private static final StringQuery returning the codes of a user that have not been spent.private static final StringStatement storing a code.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.private static final StringStatement that spends a code only when it is unused, atomically.private final RecoveryCodeRowMapperMaps a row to a code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteByUser(UUID userId) Deletes every code of a user.findUnused(UUID userId) Lists the codes of a user that have not been spent.booleanSpends a code, in one atomic step, so that two concurrent requests cannot both use it.voidreplaceAll(UUID userId, List<RecoveryCode> codes) Replaces every code of a user with a new set, which is what regenerating codes means.
-
Field Details
-
DELETE_BY_USER
Statement deleting every code of a user.- See Also:
-
INSERT
Statement storing a code.- See Also:
-
FIND_UNUSED
Query returning the codes of a user that have not been spent.- See Also:
-
MARK_USED
Statement that spends a code only when it is unused, atomically.- See Also:
-
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements. -
recoveryCodeRowMapper
Maps a row to a code.
-
-
Constructor Details
-
JdbcRecoveryCodeRepository
public JdbcRecoveryCodeRepository()
-
-
Method Details
-
replaceAll
Description copied from interface:RecoveryCodeRepositoryReplaces every code of a user with a new set, which is what regenerating codes means.- Specified by:
replaceAllin interfaceRecoveryCodeRepository- Parameters:
userId- identifier of the user.codes- the new codes.
-
findUnused
Description copied from interface:RecoveryCodeRepositoryLists the codes of a user that have not been spent.- Specified by:
findUnusedin interfaceRecoveryCodeRepository- Parameters:
userId- identifier of the user.- Returns:
- the unused codes, possibly empty.
-
markUsed
Description copied from interface:RecoveryCodeRepositorySpends a code, in one atomic step, so that two concurrent requests cannot both use it.- Specified by:
markUsedin interfaceRecoveryCodeRepository- Parameters:
id- identifier of the code.now- instant of the use.- Returns:
truewhen the code was unused and is now spent.
-
deleteByUser
Description copied from interface:RecoveryCodeRepositoryDeletes every code of a user.- Specified by:
deleteByUserin interfaceRecoveryCodeRepository- Parameters:
userId- identifier of the user.
-