Interface AccountTokenRepository


public interface AccountTokenRepository
Port that stores single-use account tokens.
  • Method Summary

    Modifier and Type
    Method
    Description
    consume(String hashedToken, String purpose, Instant now)
    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.
    int
    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.
    void
    Stores a new token.
  • Method Details

    • store

      void store(AccountToken token)
      Stores a new token.
      Parameters:
      token - the token to store.
    • findUsable

      Optional<AccountToken> 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.
      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

      Optional<AccountToken> consume(String hashedToken, String purpose, Instant now)
      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

      int deleteExpired(Instant now)
      Deletes the tokens that expired before an instant.
      Parameters:
      now - current instant.
      Returns:
      the number of deleted tokens.