Package org.forgerock.json.jose.jwk
Class JWK
- java.lang.Object
-
- org.forgerock.json.jose.jwk.JWK
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JWK.Builder<B extends JWK.Builder>
JWK builder.
-
Field Summary
Fields Modifier and Type Field Description protected static String
JSON_KEY_ALG
The Algorithm key.protected static String
JSON_KEY_KID
The KeyID key.protected static String
JSON_KEY_KTY
The KeyType key.protected static String
JSON_KEY_OPERATIONS
The KeyOperations key.protected static String
JSON_KEY_USE
The KeyUse key.protected static String
JSON_KEY_X5C
The X509 chain key.protected static String
JSON_KEY_X5T
The X509 thumbprint.protected static String
JSON_KEY_X5T_S256
The X509 SHA-256 thumbprint.protected static String
JSON_KEY_X5U
The X509 URL key.
-
Constructor Summary
Constructors Modifier Constructor Description protected
JWK(KeyType keyType, String use, String algorithm, String keyId)
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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
getAlgorithm()
Deprecated.replaced bygetJwaAlgorithm()
static Algorithm
getAlgorithm(String algorithmName)
Get the algorithm corresponding.Algorithm
getJwaAlgorithm()
Gets the alg parameter of the JWK.String
getJwkThumbprint(String hashAlgorithm)
Calculates the JWK Thumbprint of this JWK.String
getKeyId()
Gets the keyId parameter of the JWK.Set<KeyOperation>
getKeyOperations()
Gets the key operations parameter of the JWK.KeyType
getKeyType()
Gets the kty parameter of the JWK.protected abstract Optional<JWK.Builder<?>>
getPublicJwkBuilder()
Return a builder with all the values set for representing the public components of the JWK.String
getUse()
Gets the use parameter of the JWK.List<String>
getX509Chain()
Gets a List of X509 chain certs.String
getX509Thumbnail()
Deprecated.UsegetX509Thumbprint()
instead.String
getX509Thumbprint()
Gets the X509 thumbprint.String
getX509ThumbprintS256()
Gets the X.509 SHA-256 thumbprint.String
getX509URL()
Gets the X509 URL.boolean
isPrivate()
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
parse(String json)
Parses a String into the proper JWK type.static JWK
parse(JsonValue jwk)
Parses a JsonValue into the proper JWK type.protected void
putField(JsonValue jsonValue, String key, Object value)
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.String
toJsonString()
Prints the JWK Object as a json string.JsonValue
toJsonValue()
Returns a json representation of the JWK.protected static JsonValue
toJsonValue(String json)
Converts a String into a JsonValue.Optional<JWK>
toPublicJwk()
For asymmetric keys, get the public JWK representation of this JWK.
-
-
-
Field Detail
-
JSON_KEY_KTY
protected static final String JSON_KEY_KTY
The KeyType key.- See Also:
- Constant Field Values
-
JSON_KEY_USE
protected static final String JSON_KEY_USE
The KeyUse key.- See Also:
- Constant Field Values
-
JSON_KEY_OPERATIONS
protected static final String JSON_KEY_OPERATIONS
The KeyOperations key.- See Also:
- Constant Field Values
-
JSON_KEY_ALG
protected static final String JSON_KEY_ALG
The Algorithm key.- See Also:
- Constant Field Values
-
JSON_KEY_KID
protected static final String JSON_KEY_KID
The KeyID key.- See Also:
- Constant Field Values
-
JSON_KEY_X5U
protected static final String JSON_KEY_X5U
The X509 URL key.- See Also:
- Constant Field Values
-
JSON_KEY_X5T
protected static final String JSON_KEY_X5T
The X509 thumbprint.- See Also:
- Constant Field Values
-
JSON_KEY_X5C
protected static final String JSON_KEY_X5C
The X509 chain key.- See Also:
- Constant Field Values
-
JSON_KEY_X5T_S256
protected static final String JSON_KEY_X5T_S256
The X509 SHA-256 thumbprint.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JWK
@Deprecated protected JWK(KeyType keyType, String use, String algorithm, String keyId)
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 Detail
-
getKeyType
public KeyType getKeyType()
Gets the kty parameter of the JWK.- Returns:
- The KeyType for the JWK
-
getUse
public String getUse()
Gets the use parameter of the JWK.- Returns:
- The key use.
-
getKeyOperations
public Set<KeyOperation> 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 public String getAlgorithm()
Deprecated.replaced bygetJwaAlgorithm()
Gets the alg parameter of the JWK.- Returns:
- The algorithm name representing the alg parameter
-
getJwaAlgorithm
public Algorithm getJwaAlgorithm()
Gets the alg parameter of the JWK.- Returns:
- The algorithm
-
getKeyId
public String getKeyId()
Gets the keyId parameter of the JWK.- Returns:
- A String representing the keyId parameter
-
toJsonString
public String toJsonString()
Prints the JWK Object as a json string.- Returns:
- A String representing JWK
-
toJsonValue
public JsonValue toJsonValue()
Returns a json representation of the JWK.- Returns:
- A JSON representation.
-
putField
protected void putField(JsonValue jsonValue, String key, Object value)
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
public static JWK parse(String json)
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
public static JWK parse(JsonValue jwk)
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
protected static void loadJWKFromJson(JWK.Builder builder, JsonValue json)
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
public static Algorithm getAlgorithm(String algorithmName)
Get the algorithm corresponding.- Parameters:
algorithmName
- The algorithm name..- Returns:
- An algorithm
- Throws:
IllegalArgumentException
- If the algorithm is not supported.
-
toJsonValue
protected static JsonValue toJsonValue(String json)
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
public String getX509URL()
Gets the X509 URL.- Returns:
- the url of the 509 cert header or null
-
getX509Thumbprint
public String getX509Thumbprint()
Gets the X509 thumbprint.- Returns:
- Base64url of the X509 thumbprint.
-
getX509Thumbnail
@Deprecated public String getX509Thumbnail()
Deprecated.UsegetX509Thumbprint()
instead.Gets the X509 thumbprint.- Returns:
- Base64url of the X509 thumbnail
-
getX509ThumbprintS256
public String getX509ThumbprintS256()
Gets the X.509 SHA-256 thumbprint.- Returns:
- Base64url of the X.509 SHA-256 thumbprint.
-
getX509Chain
public List<String> 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
public Optional<JWK> toPublicJwk()
For asymmetric keys, get the public JWK representation of this JWK.- Returns:
- The public JWK.
-
getPublicJwkBuilder
protected abstract Optional<JWK.Builder<?>> 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
public String getJwkThumbprint(String hashAlgorithm)
Calculates the JWK Thumbprint of this JWK.- Parameters:
hashAlgorithm
- the hash algorithm, e.g. SHA-256.- Returns:
- the JWK thumbprint.
-
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.
-
-