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 Details

    • INSERT_TOKEN

      private static final String INSERT_TOKEN
      Statement storing a token.
      See Also:
    • FIND_USABLE_TOKEN

      private static final String FIND_USABLE_TOKEN
      Query returning a token only when it is unused and not expired, without changing it.
      See Also:
    • CONSUME_TOKEN

      private static final String 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 jdbcClient
      JDBC client used to run the statements.
    • accountTokenRowMapper

      private final AccountTokenRowMapper accountTokenRowMapper
      Maps a row to a token.
  • Constructor Details

    • JdbcAccountTokenRepository

      public JdbcAccountTokenRepository()
  • Method Details

    • store

      public void store(AccountToken token)
      Description copied from interface: AccountTokenRepository
      Stores a new token.
      Specified by:
      store in interface AccountTokenRepository
      Parameters:
      token - the token to store.
    • findUsable

      public Optional<AccountToken> findUsable(String hashedToken, String purpose, Instant now)
      Description copied from interface: AccountTokenRepository
      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.
      Specified by:
      findUsable in interface AccountTokenRepository
      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

      public Optional<AccountToken> consume(String hashedToken, String purpose, Instant now)
      Description copied from interface: AccountTokenRepository
      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.
      Specified by:
      consume in interface AccountTokenRepository
      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

      public int deleteExpired(Instant now)
      Description copied from interface: AccountTokenRepository
      Deletes the tokens that expired before an instant.
      Specified by:
      deleteExpired in interface AccountTokenRepository
      Parameters:
      now - current instant.
      Returns:
      the number of deleted tokens.