public class SecretBuilder extends Object
Secret
subtypes should
supply a one-argument constructor that takes an instance of this class. Secrets providers can then supply all
relevant secret material and individual types of secrets can request the material that they need. For instance, a
signature verification key would request only a public key, while the signing key would request the corresponding
private key.Constructor and Description |
---|
SecretBuilder() |
Modifier and Type | Method and Description |
---|---|
SecretBuilder |
allowedAlgorithms(Collection<String> allowedAlgorithms)
Sets the cryptographic algorithms that can be used with this key.
|
SecretBuilder |
allowedAlgorithms(Predicate<String> allowedAlgorithmsTest)
Sets the cryptographic algorithms that can be used with this key.
|
<T extends Secret> |
build(Class<T> secretType)
Builds a secret of the given type.
|
SecretBuilder |
certificate(Certificate certificate)
Sets the certificate associated with this secret.
|
SecretBuilder |
clock(Clock clock)
Set the source of time for the default (relative) secret expiry time.
|
SecretBuilder |
expiresAt(Instant expiry)
Sets the secret to expire at the given time.
|
SecretBuilder |
expiresIn(long deadline,
TemporalUnit unit,
Clock clock)
Sets the secret to expire in deadline units from now.
|
Predicate<String> |
getAllowedAlgorithms()
Returns a predicate that can be used to test whether a given algorithm can be used with this key.
|
Set<KeyUsage> |
getAllowedKeyUsages()
The allowed key usages of this key.
|
Certificate |
getCertificate()
Returns the certificate associated with this secret, or null if not available.
|
Instant |
getExpiry()
Returns the expiry time for this secret.
|
Provider |
getProvider()
Returns the security provider associated with this secret, or null if not specified.
|
PublicKey |
getPublicKey()
Returns the public key associated with this secret, or null if not available.
|
byte[] |
getRawData()
Returns the raw secret data, or null if the raw data is not available.
|
Key |
getSecretKey()
Returns the secret (or private) key associated with this secret, or null if not specified.
|
String |
getStableId()
Returns the stable id for this secret..
|
SecretBuilder |
keyUsages(Set<KeyUsage> keyUsages)
Sets the allowed key usages for this key.
|
SecretBuilder |
password(char[] password)
Sets the raw data of this secret object to the UTF-8 bytes of the given password.
|
SecretBuilder |
publicKey(PublicKey key)
Sets the public key associated with this secret.
|
SecretBuilder |
rawData(byte[] rawData)
Sets the raw data of the secret object.
|
SecretBuilder |
secretKey(Key key)
Sets the secret key for this object.
|
SecretBuilder |
stableId(String id)
Sets the stable id of this secret.
|
public SecretBuilder clock(Clock clock)
clock
- The clock to use for obtaining expiry time.public SecretBuilder stableId(String id)
id
- the stable id of the secret.public SecretBuilder expiresAt(Instant expiry)
expiry
- the expiry time of the secret.public SecretBuilder expiresIn(long deadline, TemporalUnit unit, Clock clock)
deadline
- the amount of time that this secret should be valid for.unit
- the units of the deadline.clock
- The clock to use for obtaining the expiry time.public SecretBuilder password(char[] password)
password
- the password.public SecretBuilder rawData(byte[] rawData)
GenericSecret
s.rawData
- the raw secret data.public SecretBuilder secretKey(Key key)
key
- the key object.public SecretBuilder publicKey(PublicKey key)
key
- the public key.public SecretBuilder certificate(Certificate certificate)
certificate
- the certificate.public SecretBuilder keyUsages(Set<KeyUsage> keyUsages)
keyUsages
- the allowed key usages.public SecretBuilder allowedAlgorithms(Predicate<String> allowedAlgorithmsTest)
allowedAlgorithmsTest
- a predicate to test whether a given algorithm is allowed to be used with this key.public SecretBuilder allowedAlgorithms(Collection<String> allowedAlgorithms)
Collection.contains(Object)
method on the
supplied collection, so a case-insensitive comparison can be used by specifying a case-insensitive collection.
It is recommended to use a case-insensitive collection unless case-sensitivity is mandatory for a particular
set of algorithms. The collection is not copied, so the passed collection should not be modified after calling
this method.
It is recommended that this is populated with at least the following algorithm names as a default:
SHA256WithRSA
or
AES/GCM/NoPadding
ES256
or A256KW
. Note: in the case of JWE with a
symmetric key that is intended for direct encryption (alg=dir
it is recommended to also include
the names of the relevant enc
content encryption algorithms the key is intended to be used with,
such as A256GCM
or A128CBC-HS256
.allowedAlgorithms
- the set of allowed algorithms that can be used with this key.public Set<KeyUsage> getAllowedKeyUsages()
public Predicate<String> getAllowedAlgorithms()
public String getStableId()
public Instant getExpiry()
public byte[] getRawData() throws NoSuchSecretException
NoSuchSecretException
- if the raw secret cannot be extracted.public Key getSecretKey() throws NoSuchSecretException
NoSuchSecretException
- if the secret cannot be extracted.public PublicKey getPublicKey()
public Provider getProvider()
public Certificate getCertificate()
public <T extends Secret> T build(Class<T> secretType) throws NoSuchSecretException
T
- the type of secret to build.secretType
- the type of secret to build.NoSuchSecretException
- If the secret could not be built, or one of the secrets used to unlock this secret
could not be obtained.Copyright © 2010-2018, ForgeRock All Rights Reserved.