java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.ott.JdbcOneTimeCodeRepository
All Implemented Interfaces:
OneTimeCodeRepository

@Repository public class JdbcOneTimeCodeRepository extends Object implements 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 Details

    • DELETE_BY_BINDING

      private static final String DELETE_BY_BINDING
      Statement deleting the codes of a binding and a user name.
      See Also:
    • INSERT

      private static final String INSERT
      Statement storing a code.
      See Also:
    • FIND_ACTIVE

      private static final String FIND_ACTIVE
      Query returning the newest unexpired code of a binding and a user name.
      See Also:
    • INCREMENT_ATTEMPTS

      private static final String INCREMENT_ATTEMPTS
      Statement counting a failed attempt atomically and returning the new count.
      See Also:
    • CONSUME

      private static final String CONSUME
      Statement spending a code.
      See Also:
    • DELETE_EXPIRED

      private static final String DELETE_EXPIRED
      Statement deleting the expired codes.
      See Also:
    • jdbcClient

      private final org.springframework.jdbc.core.simple.JdbcClient jdbcClient
      JDBC client used to run the statements.
    • oneTimeCodeRowMapper

      private final OneTimeCodeRowMapper oneTimeCodeRowMapper
      Maps a row to a code.
  • Constructor Details

    • JdbcOneTimeCodeRepository

      public JdbcOneTimeCodeRepository()
  • Method Details

    • save

      public void save(OneTimeCode code)
      Description copied from interface: OneTimeCodeRepository
      Stores 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:
      save in interface OneTimeCodeRepository
      Parameters:
      code - the code to store.
    • findActive

      public Optional<OneTimeCode> findActive(String bindingId, String username, Instant now)
      Description copied from interface: OneTimeCodeRepository
      Finds the code that is still active for a binding and a user.
      Specified by:
      findActive in interface OneTimeCodeRepository
      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

      public int incrementAttempts(UUID id)
      Description copied from interface: OneTimeCodeRepository
      Counts a wrong submission, in one atomic step.
      Specified by:
      incrementAttempts in interface OneTimeCodeRepository
      Parameters:
      id - identifier of the code.
      Returns:
      the number of attempts after the increment, or 0 when the code no longer exists.
    • consume

      public boolean consume(UUID id)
      Description copied from interface: OneTimeCodeRepository
      Spends a code, in one atomic step, so that two concurrent requests cannot both use it.
      Specified by:
      consume in interface OneTimeCodeRepository
      Parameters:
      id - identifier of the code.
      Returns:
      true when the code existed and is now spent.
    • deleteExpired

      public int deleteExpired(Instant now)
      Description copied from interface: OneTimeCodeRepository
      Deletes every code that has expired.
      Specified by:
      deleteExpired in interface OneTimeCodeRepository
      Parameters:
      now - current instant.
      Returns:
      the number of deleted codes.