public final class SecretsUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Key |
exportAsKey(CryptoKey cryptoKey)
Exports the key material in the raw format.
|
static Key |
exportAsKeyAndClose(CryptoKey cryptoKey)
Exports the key material in the raw format and close the provided key material.
|
static String |
getPasswordSecretIdOrPassword(SecretsService secretsService,
JsonValue secretIdNode,
JsonValue deprecatedNode,
org.slf4j.Logger logger)
Retrieve a required password value from the given
secretIdNode and deprecatedNode nodes. |
static String |
getPasswordSecretIdOrPassword(SecretsService secretsService,
JsonValue secretIdNode,
JsonValue deprecatedNode,
org.slf4j.Logger logger,
boolean isRequired)
Retrieve a password value from the given
secretIdNode and deprecatedNode nodes (can be an
optional value). |
static byte[] |
getPasswordSecretIdOrPasswordAsByte(SecretsService secretsService,
JsonValue secretIdNode,
JsonValue deprecatedNode,
org.slf4j.Logger logger)
Retrieve a required shared secret value (as
byte[] ) from the given secretIdNode
and deprecatedNode nodes. |
static <S extends CryptoKey> |
retrieveCryptoKeyFromSecretId(SecretsService secretsService,
JsonValue secretIdNode,
Class<S> type)
Retrieves a
CryptoKey from the given node. |
static <S extends CryptoKey> |
retrieveKeyFromSecretId(SecretsService secretsService,
JsonValue secretIdNode,
Class<S> type)
Retrieves a
Key from the given node. |
static SecretReference<GenericSecret> |
retrievePasswordAsReference(SecretsService secretsService,
JsonValue secretIdNode,
JsonValue deprecatedNode,
Clock clock)
Retrieve a required password as a
SecretReference from the given secretIdNode
and deprecatedNode nodes. |
public static String getPasswordSecretIdOrPassword(SecretsService secretsService, JsonValue secretIdNode, JsonValue deprecatedNode, org.slf4j.Logger logger) throws NoSuchSecretException
secretIdNode
and deprecatedNode
nodes.
secretIdNode
node has precedence.NoSuchSecretException
is throwndeprecatedNode
) is returnedThis method logs deprecation warnings if password is resolved from the deprecatedNode
node value.
secretsService
- The SecretsService
used to retrieve the secret.secretIdNode
- The node describing the Purpose
where the password will be available.deprecatedNode
- The deprecated node holding the password. Deprecated since 6.5.logger
- The logger used to display warnings and other deprecation messages.String
representing the password.NoSuchSecretException
- If secret reference cannot be resolved.public static String getPasswordSecretIdOrPassword(SecretsService secretsService, JsonValue secretIdNode, JsonValue deprecatedNode, org.slf4j.Logger logger, boolean isRequired) throws NoSuchSecretException
secretIdNode
and deprecatedNode
nodes (can be an
optional value).
secretIdNode
node has precedence.NoSuchSecretException
is throwndeprecatedNode
) is returnednull
is returnedThis method logs deprecation warnings if password is resolved from the deprecatedNode
node value.
secretsService
- The SecretsService
used to retrieve the secret.secretIdNode
- The node describing the Purpose
where the password will be available.deprecatedNode
- The deprecated node holding the password. Deprecated since 6.5.logger
- The logger used to display warnings and other deprecation messages.isRequired
- If set to true
, this method will throw an exception if deprecatedNode
has a null value.String
representing the password (or null
if no node value is provided).NoSuchSecretException
- If secret reference cannot be resolved.public static byte[] getPasswordSecretIdOrPasswordAsByte(SecretsService secretsService, JsonValue secretIdNode, JsonValue deprecatedNode, org.slf4j.Logger logger) throws NoSuchSecretException
byte[]
) from the given secretIdNode
and deprecatedNode
nodes.
secretIdNode
node has precedence.NoSuchSecretException
is throwndeprecatedNode
) is returnedThis method logs deprecation warnings if shared secret is resolved from the deprecatedNode
node value.
secretsService
- The SecretsService
used to retrieve the secret.secretIdNode
- The node describing the Purpose
where the password will be available.deprecatedNode
- The deprecated node holding the password. Deprecated since 6.5.logger
- The logger used to display warnings and other deprecation messages.String
representing the password.NoSuchSecretException
- If secret reference cannot be resolved.public static <S extends CryptoKey> Key retrieveKeyFromSecretId(SecretsService secretsService, JsonValue secretIdNode, Class<S> type) throws NoSuchSecretException
Key
from the given node.S
- The type of the secret.secretsService
- The SecretsService
used to retrieve the secret.secretIdNode
- The secretId node.type
- The expected type of the secret.Key
if the secret is found.NoSuchSecretException
- If there is no corresponding key.public static Key exportAsKey(CryptoKey cryptoKey) throws NoSuchSecretException
cryptoKey
- The key material to exportNoSuchSecretException
- if the secret could not be exported.public static Key exportAsKeyAndClose(CryptoKey cryptoKey) throws NoSuchSecretException
cryptoKey
- The key material to exportNoSuchSecretException
- if the secret could not be exported.public static <S extends CryptoKey> S retrieveCryptoKeyFromSecretId(SecretsService secretsService, JsonValue secretIdNode, Class<S> type) throws NoSuchSecretException
CryptoKey
from the given node.S
- The type of the secret.secretsService
- The SecretsService
used to retrieve the secret.secretIdNode
- The secretId node.type
- The expected type of the secret.CryptoKey
if the secret is found.NoSuchSecretException
- If there is no corresponding key.public static SecretReference<GenericSecret> retrievePasswordAsReference(SecretsService secretsService, JsonValue secretIdNode, JsonValue deprecatedNode, Clock clock) throws NoSuchSecretException
SecretReference
from the given secretIdNode
and deprecatedNode
nodes.
secretIdNode
node has precedence.NoSuchSecretException
is throwndeprecatedNode
) is returnedsecretsService
- A reference to the SecretsService
holding references to secret ID.secretIdNode
- The node describing the Purpose
where the password will be available.deprecatedNode
- The deprecated node holding the password. Deprecated since 6.5.clock
- A reference to the current Clock
.SecretReference
to this password.NoSuchSecretException
- when the secret ID cannot be resolved.Copyright 2011-2017 ForgeRock AS.