Class JdbcOneTimeCodeRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.ott.JdbcOneTimeCodeRepository
- All Implemented Interfaces:
OneTimeCodeRepository
OneTimeCodeRepository over the ott_codes table. It opens no transaction: replacing a code runs in
the caller's, and every other operation is a single statement.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringStatement spending a code.private static final StringStatement deleting the codes of a binding and a user name.private static final StringStatement deleting the expired codes.private static final StringQuery returning the newest unexpired code of a binding and a user name.private static final StringStatement counting a failed attempt atomically and returning the new count.private static final StringStatement storing a code.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.private final OneTimeCodeRowMapperMaps a row to a code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanSpends a code, in one atomic step, so that two concurrent requests cannot both use it.intdeleteExpired(Instant now) Deletes every code that has expired.findActive(String bindingId, String username, Instant now) Finds the code that is still active for a binding and a user.intCounts a wrong submission, in one atomic step.voidsave(OneTimeCode code) Stores a code, replacing any other active code of the same binding and user name so that only the latest one can be used.
-
Field Details
-
DELETE_BY_BINDING
Statement deleting the codes of a binding and a user name.- See Also:
-
INSERT
Statement storing a code.- See Also:
-
FIND_ACTIVE
Query returning the newest unexpired code of a binding and a user name.- See Also:
-
INCREMENT_ATTEMPTS
Statement counting a failed attempt atomically and returning the new count.- See Also:
-
CONSUME
Statement spending a code.- See Also:
-
DELETE_EXPIRED
Statement deleting the expired codes.- See Also:
-
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements. -
oneTimeCodeRowMapper
Maps a row to a code.
-
-
Constructor Details
-
JdbcOneTimeCodeRepository
public JdbcOneTimeCodeRepository()
-
-
Method Details
-
save
Description copied from interface:OneTimeCodeRepositoryStores a code, replacing any other active code of the same binding and user name so that only the latest one can be used.- Specified by:
savein interfaceOneTimeCodeRepository- Parameters:
code- the code to store.
-
findActive
Description copied from interface:OneTimeCodeRepositoryFinds the code that is still active for a binding and a user.- Specified by:
findActivein interfaceOneTimeCodeRepository- Parameters:
bindingId- identifier binding the code to the requesting browser session.username- user name of the account.now- current instant; an expired code is not active.- Returns:
- the active code, or empty when there is none.
-
incrementAttempts
Description copied from interface:OneTimeCodeRepositoryCounts a wrong submission, in one atomic step.- Specified by:
incrementAttemptsin interfaceOneTimeCodeRepository- Parameters:
id- identifier of the code.- Returns:
- the number of attempts after the increment, or
0when the code no longer exists.
-
consume
Description copied from interface:OneTimeCodeRepositorySpends a code, in one atomic step, so that two concurrent requests cannot both use it.- Specified by:
consumein interfaceOneTimeCodeRepository- Parameters:
id- identifier of the code.- Returns:
truewhen the code existed and is now spent.
-
deleteExpired
Description copied from interface:OneTimeCodeRepositoryDeletes every code that has expired.- Specified by:
deleteExpiredin interfaceOneTimeCodeRepository- Parameters:
now- current instant.- Returns:
- the number of deleted codes.
-