Package org.forgerock.json.jose.jwt
Class JwtHeader
java.lang.Object
org.forgerock.json.jose.jwt.JWObject
org.forgerock.json.jose.jwt.JwtHeader
- Direct Known Subclasses:
JwtSecureHeader
A base implementation class for JWT Headers.
Provides methods to set header parameters for all types of JWT Headers.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds the JWT's header into aString
representation of a JSON object.abstract Algorithm
Gets the Algorithm set in the JWT header.protected String
Gets the string representation of the Algorithm set in the JWT header.getParameter
(String key) Gets a header parameter for the specified key.<T> T
getParameter
(String key, Class<T> clazz) Gets a header parameter for the specified key and then casts it to the specified type.Returns this JwtHeader's parameters.getType()
Gets the type of JWT this header represents.void
setAlgorithm
(Algorithm algorithm) Sets the algorithm used to perform cryptographic signing and/or encryption on the JWT.void
setParameter
(String key, Object value) Sets a header parameter with the specified key and value.void
setParameters
(Map<String, Object> headers) Sets header parameters using the values contained in the specified map.void
Sets the type of JWT this header represents.Methods inherited from class org.forgerock.json.jose.jwt.JWObject
checkListValuesAreOfType, checkValueIsOfType, equals, get, hashCode, isDefined, isValueOfType, keys, put, toJsonValue, toString
-
Constructor Details
-
JwtHeader
public JwtHeader()Constructs a new JwtHeader, with the "typ" parameter set to "JWT". -
JwtHeader
Constructs a new JwtHeader, with its parameters set to the contents of the given Map.- Parameters:
headers
- A Map containing the parameters to be set in the header.
-
-
Method Details
-
setType
Sets the type of JWT this header represents.For non-nested JWTs then the "JWT" type is RECOMMENDED to be used but it is OPTIONAL to set the "typ" property. For nested signed or encrypted JWTs the JWT type MUST be "JWS" and "JWE" respectively and the "typ" property MUST be set.
- Parameters:
jwtType
- The JwtType.- See Also:
-
getType
Gets the type of JWT this header represents.- Returns:
- The JwtType.
-
setAlgorithm
Sets the algorithm used to perform cryptographic signing and/or encryption on the JWT.- Parameters:
algorithm
- The Algorithm.
-
getAlgorithm
Gets the Algorithm set in the JWT header.- Returns:
- The Algorithm.
-
getAlgorithmString
Gets the string representation of the Algorithm set in the JWT header.- Returns:
- The algorithm as a String.
-
setParameter
Sets a header parameter with the specified key and value.If the key matches one of the reserved header parameter names, then the relevant
set
method is called to set that header parameter with the specified value.- Parameters:
key
- The key of the header parameter.value
- The value of the header parameter.
-
setParameters
Sets header parameters using the values contained in the specified map.- Parameters:
headers
- The Map to use to set header parameters.- See Also:
-
getParameter
Gets a header parameter for the specified key.If the key matches one of the reserved header parameter names, then the relevant
get
method is called to get that header parameter.- Parameters:
key
- The header parameter key.- Returns:
- The value stored against the header parameter key.
-
getParameter
Gets a header parameter for the specified key and then casts it to the specified type.- Type Parameters:
T
- The required type for the header parameter value.- Parameters:
key
- The header parameter key.clazz
- The class of the required type.- Returns:
- The value stored against the header parameter key.
- See Also:
-
getParameters
Returns this JwtHeader's parameters.- Returns:
Map
of this JwtHeader's parameters.
-
build
Builds the JWT's header into aString
representation of a JSON object.- Returns:
- A JSON string.
-