java.lang.Object
io.helidon.security.jwt.JwtUtil
Utilities for JWT and JWK parsing.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Address class representing the JSON object for address. -
Method Summary
Modifier and TypeMethodDescriptionstatic BigInteger
asBigInteger
(JsonObject json, String key, String description) Extract a key value from json object that is base64-url encoded and convert it to big integer.static byte[]
asByteArray
(JsonObject json, String key, String description) Extract a key value from json object that is a base64-url encoded byte array.static String
asString
(JsonObject json, String key, String description) Extract a key value from json object that is string.static Optional<BigInteger>
getBigInteger
(JsonObject json, String key, String description) Extract a key value from json object that is base64-url encoded and convert it to big integer if present.static Optional<byte[]>
getByteArray
(JsonObject json, String key, String description) Extract a key value from json object that is a base64-url encoded byte array, if present.static KeyFactory
getKeyFactory
(String algorithm) Create a key factory for algorithm.static Mac
Create a MAC for algorithm.static Signature
getSignature
(String signatureAlgorithm) Create a signature for algorithm.getString
(JsonObject json, String key) Extract a key value from json object that is string if present.getStrings
(JsonObject json, String key) Extract a key value from json object that is a list of strings if present.static JsonValue
Create aJsonValue
from an object.static Object
Transform from json to object.transformToJson
(Map<String, Object> claims) Transform a map of strings to objects to a map of string to JSON values.
-
Method Details
-
asBigInteger
public static BigInteger asBigInteger(JsonObject json, String key, String description) throws JwtException Extract a key value from json object that is base64-url encoded and convert it to big integer.- Parameters:
json
- JsonObject to read key fromkey
- key of the value we want to readdescription
- description of the field for error handling- Returns:
- BigInteger value
- Throws:
JwtException
- in case the key is not present or is of invalid content
-
asString
Extract a key value from json object that is string.- Parameters:
json
- JsonObject to read key fromkey
- key of the value we want to readdescription
- description of the field for error handling- Returns:
- String value
- Throws:
JwtException
- in case the key is not present or is of invalid content
-
getBigInteger
public static Optional<BigInteger> getBigInteger(JsonObject json, String key, String description) throws JwtException Extract a key value from json object that is base64-url encoded and convert it to big integer if present.- Parameters:
json
- JsonObject to read key fromkey
- key of the value we want to readdescription
- description of the field for error handling- Returns:
- BigInteger value if present
- Throws:
JwtException
- in case the key is of invalid content
-
getStrings
Extract a key value from json object that is a list of strings if present.- Parameters:
json
- JsonObject to read key fromkey
- key of the value we want to read- Returns:
- List of String value if present
- Throws:
JwtException
- in case the key is of invalid content
-
getString
Extract a key value from json object that is string if present.- Parameters:
json
- JsonObject to read key fromkey
- key of the value we want to read- Returns:
- String value if present
- Throws:
JwtException
- in case the key is of invalid content
-
getByteArray
public static Optional<byte[]> getByteArray(JsonObject json, String key, String description) throws JwtException Extract a key value from json object that is a base64-url encoded byte array, if present.- Parameters:
json
- JsonObject to read key fromkey
- key of the value we want to readdescription
- description of the field for error handling- Returns:
- byte array value if present
- Throws:
JwtException
- in case the key is of invalid content or not base64 encoded
-
asByteArray
public static byte[] asByteArray(JsonObject json, String key, String description) throws JwtException Extract a key value from json object that is a base64-url encoded byte array.- Parameters:
json
- JsonObject to read key fromkey
- key of the value we want to readdescription
- description of the field for error handling- Returns:
- byte array value
- Throws:
JwtException
- in case the key is not present, is of invalid content or not base64 encoded
-
getKeyFactory
Create a key factory for algorithm.- Parameters:
algorithm
- security algorithm (such as RSA, EC)- Returns:
- KeyFactory instance
- Throws:
JwtException
- in case the algorithm is invalid
-
getSignature
Create a signature for algorithm.- Parameters:
signatureAlgorithm
- security signature algorithm (such as "SHA512withRSA")- Returns:
- Signature instance
- Throws:
JwtException
- in case the algorithm is invalid or not supported by this JVM
-
getMac
Create a MAC for algorithm. Similar to signature for symmetric ciphers (such as "HmacSHA256").- Parameters:
algorithm
- security MAC algorithm- Returns:
- Mac instance
- Throws:
JwtException
- in case the algorithm is invalid or not supported by this JVM
-
transformToJson
Transform a map of strings to objects to a map of string to JSON values. Each object is checked for type and if supported, transformed to appropriate JSON value.- Parameters:
claims
- map to transform from- Returns:
- resulting map
-
toJson
Create aJsonValue
from an object. This will use correct types for known primitives,JwtUtil.Address
otherwise it uses String value.- Parameters:
object
- object to create json value from- Returns:
- json value
-
toObject
Transform from json to object.- Parameters:
jsonValue
- json value- Returns:
- object most correct for the type, or string value if not understood (e.g. json object)
-