Package io.helidon.security.jwt
Class JwtUtil
- java.lang.Object
-
- io.helidon.security.jwt.JwtUtil
-
public final class JwtUtil extends Object
Utilities for JWT and JWK parsing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JwtUtil.Address
Address class representing the JSON object for address.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
getMac(String algorithm)
Create a MAC for algorithm.static Signature
getSignature(String signatureAlgorithm)
Create a signature for algorithm.static Optional<String>
getString(JsonObject json, String key)
Extract a key value from json object that is string if present.static Optional<List<String>>
getStrings(JsonObject json, String key)
Extract a key value from json object that is a list of strings if present.static Object
toObject(JsonValue jsonValue)
Transform from json to object.static Map<String,JsonValue>
transformToJson(Map<String,Object> claims)
Transform a map of strings to objects to a map of string to JSON values.
-
-
-
Method Detail
-
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
public static String asString(JsonObject json, String key, String description) throws JwtException
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
public static Optional<List<String>> getStrings(JsonObject json, String key) throws JwtException
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
public static Optional<String> getString(JsonObject json, String key) throws JwtException
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
public static KeyFactory getKeyFactory(String algorithm) throws JwtException
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
public static Signature getSignature(String signatureAlgorithm) throws JwtException
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
public static Mac getMac(String algorithm) throws JwtException
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
public static Map<String,JsonValue> transformToJson(Map<String,Object> claims)
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
-
-