Package org.forgerock.json.jose.jwk
Class JWK
java.lang.Object
org.forgerock.json.jose.jwk.JWK
The abstract base class for the 3 implementations of JWK.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
The Algorithm key.protected static final String
The KeyID key.protected static final String
The KeyType key.protected static final String
The KeyOperations key.protected static final String
The KeyUse key.protected static final String
The X509 chain key.protected static final String
The X509 thumbprint.protected static final String
The X509 SHA-256 thumbprint.protected static final String
The X509 URL key. -
Constructor Summary
ModifierConstructorDescriptionprotected
Deprecated.Use the builder instead.protected
JWK
(KeyType keyType, String use, String algorithm, String keyId, String x509url, String x509Thumbprint, List<String> x509Chain) Deprecated.Use the builder instead.protected
JWK
(KeyType keyType, String use, Set<KeyOperation> keyOperations, Algorithm algorithm, String keyId, String x509url, String x509Thumbprint, List<String> x509Chain) Creates a JWK given the basic parameters. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.replaced bygetJwaAlgorithm()
static Algorithm
getAlgorithm
(String algorithmName) Get the algorithm corresponding.Gets the alg parameter of the JWK.getJwkThumbprint
(String hashAlgorithm) Calculates the JWK Thumbprint of this JWK.getKeyId()
Gets the keyId parameter of the JWK.Gets the key operations parameter of the JWK.Gets the kty parameter of the JWK.protected abstract Optional<JWK.Builder<?>>
Return a builder with all the values set for representing the public components of the JWK.getUse()
Gets the use parameter of the JWK.Gets a List of X509 chain certs.Deprecated.UsegetX509Thumbprint()
instead.Gets the X509 thumbprint.Gets the X.509 SHA-256 thumbprint.Gets the X509 URL.boolean
Indicates if any private key attributes are present in the JWK.protected static void
loadJWKFromJson
(JWK.Builder builder, JsonValue json) Load the generic JWK attributes from the json, by side effect.static JWK
Parses a String into the proper JWK type.static JWK
Parses a JsonValue into the proper JWK type.protected void
Add a string value into a json only if it's not null.<T extends CryptoKey>
TtoCryptoKey
(Purpose<T> purpose, Instant expiry) Converts this JWK into aCryptoKey
subclass object for use with the Secrets API.Prints the JWK Object as a json string.Returns a json representation of the JWK.protected static JsonValue
toJsonValue
(String json) Converts a String into a JsonValue.For asymmetric keys, get the public JWK representation of this JWK.Get aSecretBuilder
capable of building aSecret
subclass object from this JWK.
-
Field Details
-
JSON_KEY_KTY
The KeyType key.- See Also:
-
JSON_KEY_USE
The KeyUse key.- See Also:
-
JSON_KEY_OPERATIONS
The KeyOperations key.- See Also:
-
JSON_KEY_ALG
The Algorithm key.- See Also:
-
JSON_KEY_KID
The KeyID key.- See Also:
-
JSON_KEY_X5U
The X509 URL key.- See Also:
-
JSON_KEY_X5T
The X509 thumbprint.- See Also:
-
JSON_KEY_X5C
The X509 chain key.- See Also:
-
JSON_KEY_X5T_S256
The X509 SHA-256 thumbprint.- See Also:
-
-
Constructor Details
-
JWK
Deprecated.Use the builder instead.Creates a JWK given the basic parameters.- Parameters:
keyType
- the JWK key typeuse
- the JWK usealgorithm
- the JWK algorithmkeyId
- the JWK key id
-
JWK
@Deprecated protected JWK(KeyType keyType, String use, String algorithm, String keyId, String x509url, String x509Thumbprint, List<String> x509Chain) Deprecated.Use the builder instead.Creates a JWK given the basic parameters.- Parameters:
keyType
- the JWK key typeuse
- the JWK usealgorithm
- the JWK algorithmkeyId
- the JWK key idx509url
- the x509 url for the keyx509Thumbprint
- the x509 thumbnail for the keyx509Chain
- the x509 chain as a list of Base64 encoded strings
-
JWK
protected JWK(KeyType keyType, String use, Set<KeyOperation> keyOperations, Algorithm algorithm, String keyId, String x509url, String x509Thumbprint, List<String> x509Chain) Creates a JWK given the basic parameters.- Parameters:
keyType
- the JWK key typeuse
- the JWK usekeyOperations
- the JWK key Operationsalgorithm
- the JWK algorithmkeyId
- the JWK key idx509url
- the x509 url for the keyx509Thumbprint
- the x509 thumbprint for the keyx509Chain
- the x509 chain as a list of Base64 encoded strings
-
-
Method Details
-
getKeyType
Gets the kty parameter of the JWK.- Returns:
- The KeyType for the JWK
-
getUse
Gets the use parameter of the JWK.- Returns:
- The key use.
-
getKeyOperations
Gets the key operations parameter of the JWK.- Returns:
- A possibly
null
set of key operations representing the key operations parameter. Ifnull
, then all operations are allowed. An empty set mean that no key operations are allowed.
-
getAlgorithm
Deprecated.replaced bygetJwaAlgorithm()
Gets the alg parameter of the JWK.- Returns:
- The algorithm name representing the alg parameter
-
getJwaAlgorithm
Gets the alg parameter of the JWK.- Returns:
- The algorithm
-
getKeyId
Gets the keyId parameter of the JWK.- Returns:
- A String representing the keyId parameter
-
toJsonString
Prints the JWK Object as a json string.- Returns:
- A String representing JWK
-
toJsonValue
Returns a json representation of the JWK.- Returns:
- A JSON representation.
-
putField
Add a string value into a json only if it's not null.- Parameters:
jsonValue
- the jsonkey
- theMap
key orList
index identifying the child value to set.value
- the value to assign to the member.
-
parse
Parses a String into the proper JWK type.- Parameters:
json
- The json String.- Returns:
- A JWK object
- Throws:
JsonException
- If there is a problem parsing the json String.
-
parse
Parses a JsonValue into the proper JWK type.- Parameters:
jwk
- The JsonValue Object.- Returns:
- A JWK object
- Throws:
JsonException
- If there is a problem analyzing the JsonValue Object.
-
loadJWKFromJson
Load the generic JWK attributes from the json, by side effect.- Parameters:
builder
- builder will be modified by side effect.json
- the json value.
-
getAlgorithm
Get the algorithm corresponding.- Parameters:
algorithmName
- The algorithm name..- Returns:
- An algorithm
- Throws:
IllegalArgumentException
- If the algorithm is not supported.
-
toJsonValue
Converts a String into a JsonValue.- Parameters:
json
- The json String.- Returns:
- A JsonValue object.
- Throws:
JsonException
- If there is a problem parsing the json String.
-
getX509URL
Gets the X509 URL.- Returns:
- the url of the 509 cert header or null
-
getX509Thumbprint
Gets the X509 thumbprint.- Returns:
- Base64url of the X509 thumbprint.
-
getX509Thumbnail
Deprecated.UsegetX509Thumbprint()
instead.Gets the X509 thumbprint.- Returns:
- Base64url of the X509 thumbnail
-
getX509ThumbprintS256
Gets the X.509 SHA-256 thumbprint.- Returns:
- Base64url of the X.509 SHA-256 thumbprint.
-
getX509Chain
Gets a List of X509 chain certs.- Returns:
- X509 Cert Chain as list of encoded strings or null if none are available.
-
isPrivate
public boolean isPrivate()Indicates if any private key attributes are present in the JWK.- Returns:
- true if this JWK contains any private key attributes.
-
toPublicJwk
For asymmetric keys, get the public JWK representation of this JWK.- Returns:
- The public JWK.
-
getPublicJwkBuilder
Return a builder with all the values set for representing the public components of the JWK. Common JWK attributes will be added intoPublicJwk()
.- Returns:
- The builder.
-
getJwkThumbprint
Calculates the JWK Thumbprint of this JWK.- Parameters:
hashAlgorithm
- the hash algorithm, e.g. SHA-256.- Returns:
- the JWK thumbprint.
-
toSecretBuilder
Get aSecretBuilder
capable of building aSecret
subclass object from this JWK. Public and private key material is copied to the resulting object, as is any certificate chain. Any algorithm or key usage constraints are also applied to the resulting key object.- Returns:
- A
SecretBuilder
capable of building a secret.
-
toCryptoKey
public <T extends CryptoKey> T toCryptoKey(Purpose<T> purpose, Instant expiry) throws NoSuchSecretException Converts this JWK into aCryptoKey
subclass object for use with the Secrets API. Public and private key material is copied to the resulting object, as is any certificate chain. Any algorithm or key usage constraints are also applied to the resulting key object.- Type Parameters:
T
- the type of key to be built.- Parameters:
purpose
- the purpose that the key will be used for.expiry
- the expiry time for the resulting key object.- Returns:
- the constructed key object.
- Throws:
NoSuchSecretException
- if the key cannot be built for any reason, is is not allowed to be used for the given purpose.
-