java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.keys.JdbcSigningKeyRepository
All Implemented Interfaces:
SigningKeyRepository

@Repository public class JdbcSigningKeyRepository extends Object implements SigningKeyRepository
SigningKeyRepository over the signing_keys table. Rotation is serialised across application instances with a PostgreSQL transaction-level advisory lock.
  • Field Details

    • ROTATION_LOCK_KEY

      static final long ROTATION_LOCK_KEY
      Key of the advisory lock that serialises rotations.
      See Also:
    • FIND_ALL

      private static final String FIND_ALL
      Query returning every key, oldest first.
      See Also:
    • UPSERT

      private static final String UPSERT
      Statement inserting a key, or replacing the state of the key that has the same kid.
      See Also:
    • jdbcClient

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

      private final org.springframework.transaction.support.TransactionTemplate transactionTemplate
      Template that runs the rotation inside a transaction.
    • signingKeyRowMapper

      private final SigningKeyRowMapper signingKeyRowMapper
      Maps a row to a key.
  • Constructor Details

    • JdbcSigningKeyRepository

      public JdbcSigningKeyRepository()
  • Method Details

    • findAll

      public List<SigningKey> findAll()
      Description copied from interface: SigningKeyRepository
      Finds every stored key.
      Specified by:
      findAll in interface SigningKeyRepository
      Returns:
      the keys, in no particular order; empty when there are none.
    • save

      public void save(SigningKey key)
      Description copied from interface: SigningKeyRepository
      Inserts a key, or replaces the stored key that has the same identifier.
      Specified by:
      save in interface SigningKeyRepository
      Parameters:
      key - the key to store.
    • deleteByKid

      public void deleteByKid(String kid)
      Description copied from interface: SigningKeyRepository
      Deletes a key.
      Specified by:
      deleteByKid in interface SigningKeyRepository
      Parameters:
      kid - identifier of the key.
    • withRotationLock

      public <T> T withRotationLock(Supplier<T> action)
      Description copied from interface: SigningKeyRepository
      Runs an action while holding the cluster-wide rotation lock and inside one transaction, so that two instances can never rotate the keys at the same time. The action's changes are committed together, or not at all.
      Specified by:
      withRotationLock in interface SigningKeyRepository
      Type Parameters:
      T - type of the result.
      Parameters:
      action - the action to run.
      Returns:
      what the action returns.