Class JdbcAccountTokenRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.account.JdbcAccountTokenRepository
- All Implemented Interfaces:
AccountTokenRepository
@Repository
public class JdbcAccountTokenRepository
extends Object
implements AccountTokenRepository
AccountTokenRepository over the account_tokens table.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AccountTokenRowMapperMaps a row to a token.private static final StringStatement that marks a token as used and returns it, only when it is unused and not expired.private static final StringQuery returning a token only when it is unused and not expired, without changing it.private static final StringStatement storing a token.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConsumes a token: finds an unused, unexpired token with the given hash and purpose and marks it as used, in one atomic step, so that two concurrent calls can never both succeed.intdeleteExpired(Instant now) Deletes the tokens that expired before an instant.findUsable(String hashedToken, String purpose, Instant now) Finds an unused, unexpired token with the given hash and purpose, without consuming it, so that a caller can run every check before spending the token.voidstore(AccountToken token) Stores a new token.
-
Field Details
-
INSERT_TOKEN
Statement storing a token.- See Also:
-
FIND_USABLE_TOKEN
Query returning a token only when it is unused and not expired, without changing it.- See Also:
-
CONSUME_TOKEN
Statement that marks a token as used and returns it, only when it is unused and not expired.- See Also:
-
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements. -
accountTokenRowMapper
Maps a row to a token.
-
-
Constructor Details
-
JdbcAccountTokenRepository
public JdbcAccountTokenRepository()
-
-
Method Details
-
store
Description copied from interface:AccountTokenRepositoryStores a new token.- Specified by:
storein interfaceAccountTokenRepository- Parameters:
token- the token to store.
-
findUsable
Description copied from interface:AccountTokenRepositoryFinds an unused, unexpired token with the given hash and purpose, without consuming it, so that a caller can run every check before spending the token.- Specified by:
findUsablein interfaceAccountTokenRepository- Parameters:
hashedToken- hash of the token value.purpose- purpose the token must have.now- current instant, compared against the expiry.- Returns:
- the token, or an empty optional when there is no such usable token.
-
consume
Description copied from interface:AccountTokenRepositoryConsumes a token: finds an unused, unexpired token with the given hash and purpose and marks it as used, in one atomic step, so that two concurrent calls can never both succeed.- Specified by:
consumein interfaceAccountTokenRepository- Parameters:
hashedToken- hash of the token value.purpose- purpose the token must have.now- current instant, compared against the expiry.- Returns:
- the consumed token, or an empty optional when there is no such usable token.
-
deleteExpired
Description copied from interface:AccountTokenRepositoryDeletes the tokens that expired before an instant.- Specified by:
deleteExpiredin interfaceAccountTokenRepository- Parameters:
now- current instant.- Returns:
- the number of deleted tokens.
-