Interface AccountTokenRepository
public interface AccountTokenRepository
Port that stores single-use account tokens.
-
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.
-
Method Details
-
store
Stores a new token.- Parameters:
token- the token to store.
-
findUsable
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.- 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
Consumes 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.- 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
Deletes the tokens that expired before an instant.- Parameters:
now- current instant.- Returns:
- the number of deleted tokens.
-