Class JdbcSigningKeyRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.keys.JdbcSigningKeyRepository
- All Implemented Interfaces:
SigningKeyRepository
SigningKeyRepository over the signing_keys table. Rotation is serialised across application
instances with a PostgreSQL transaction-level advisory lock.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringQuery returning every key, oldest first.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.(package private) static final longKey of the advisory lock that serialises rotations.private final SigningKeyRowMapperMaps a row to a key.private final org.springframework.transaction.support.TransactionTemplateTemplate that runs the rotation inside a transaction.private static final StringStatement inserting a key, or replacing the state of the key that has the same kid. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteByKid(String kid) Deletes a key.findAll()Finds every stored key.voidsave(SigningKey key) Inserts a key, or replaces the stored key that has the same identifier.<T> TwithRotationLock(Supplier<T> action) 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.
-
Field Details
-
ROTATION_LOCK_KEY
static final long ROTATION_LOCK_KEYKey of the advisory lock that serialises rotations.- See Also:
-
FIND_ALL
Query returning every key, oldest first.- See Also:
-
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 jdbcClientJDBC client used to run the statements. -
transactionTemplate
private final org.springframework.transaction.support.TransactionTemplate transactionTemplateTemplate that runs the rotation inside a transaction. -
signingKeyRowMapper
Maps a row to a key.
-
-
Constructor Details
-
JdbcSigningKeyRepository
public JdbcSigningKeyRepository()
-
-
Method Details
-
findAll
Description copied from interface:SigningKeyRepositoryFinds every stored key.- Specified by:
findAllin interfaceSigningKeyRepository- Returns:
- the keys, in no particular order; empty when there are none.
-
save
Description copied from interface:SigningKeyRepositoryInserts a key, or replaces the stored key that has the same identifier.- Specified by:
savein interfaceSigningKeyRepository- Parameters:
key- the key to store.
-
deleteByKid
Description copied from interface:SigningKeyRepositoryDeletes a key.- Specified by:
deleteByKidin interfaceSigningKeyRepository- Parameters:
kid- identifier of the key.
-
withRotationLock
Description copied from interface:SigningKeyRepositoryRuns 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:
withRotationLockin interfaceSigningKeyRepository- Type Parameters:
T- type of the result.- Parameters:
action- the action to run.- Returns:
- what the action returns.
-