public class SecretsServiceProvider extends SecretsProvider
SecretsService
as a SecretsProvider
.Constructor and Description |
---|
SecretsServiceProvider(SecretsService secretsService)
Constructs an adapter around SecretsService so we can use it as a SecretProvider.
|
Modifier and Type | Method and Description |
---|---|
<S extends Secret> |
getActiveSecret(Purpose<S> purpose)
Gets the currently active secret for the given purpose.
|
<S extends Secret> |
getNamedOrValidSecrets(Purpose<S> purpose,
String id)
If the given id is not null, then this returns the single named secret that corresponds to that stable id (or
a stream of valid secrets for the given
purpose if no such secret exists), otherwise it returns all
valid secrets for the given purpose. |
<S extends Secret> |
getNamedSecret(Purpose<S> purpose,
String id)
Gets the secret for the given purpose with the given stable secret id.
|
<S extends Secret> |
getValidSecrets(Purpose<S> purpose)
Returns all secrets for the given purpose which have not yet expired.
|
setActiveStore, setActiveStore, setDefaultStores
public SecretsServiceProvider(SecretsService secretsService)
secretsService
- The SecretsService instance to wrap.public <S extends Secret> Promise<S,NoSuchSecretException> getActiveSecret(Purpose<S> purpose)
SecretsProvider
NoSuchSecretException
is thrown instead.
The active secret is found by first consulting the currently active store for the purpose label. If no active stores exist for the purpose, all default stores are consulted, and the first matching secret is used.
getActiveSecret
in class SecretsProvider
S
- the type of secret to return.purpose
- the purpose for which the secret is intended to be used.NoSuchSecretException
if
one cannot be found.public <S extends Secret> Promise<S,NoSuchSecretException> getNamedSecret(Purpose<S> purpose, String id)
SecretsProvider
getNamedSecret
in class SecretsProvider
S
- the type of secret to returnpurpose
- the purpose for which the secret is intended to be used.id
- the stable id of the particular secret to get.Secret.getStableId()
public <S extends Secret> Promise<Stream<S>,NeverThrowsException> getValidSecrets(Purpose<S> purpose)
SecretsProvider
getValidSecrets
in class SecretsProvider
S
- the type of secret to return.purpose
- the purpose for which the secrets are intended for.public <S extends Secret> Promise<Stream<S>,NeverThrowsException> getNamedOrValidSecrets(Purpose<S> purpose, String id)
SecretsProvider
purpose
if no such secret exists), otherwise it returns all
valid secrets for the given purpose. This is a convenience method for a frequent case where you want to
process an incoming message (e.g., to decrypt or verify it) and the message may or may not have a secret/key
identifier.
For example, to verify a JSON Web Token that might have a "kid" claim, we can do:
SignedJwt jwt = ...;
secrets.getNamedOrValidSecrets(Purpose.VERIFY, jwt.getHeader().getKeyId())
.map(rethrowFunction(key -> signingManager.newVerificationHandler(key)))
.anyMatch(jwt::verify);
getNamedOrValidSecrets
in class SecretsProvider
S
- the type of secrets to return.purpose
- the purpose for which the secrets are intended.id
- the optional stable id of the secret, or null if not known.Copyright 2011-2017 ForgeRock AS.