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
public abstract class JwtHeader extends JWObject
A base implementation class for JWT Headers.Provides methods to set header parameters for all types of JWT Headers.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Stringbuild()Builds the JWT's header into aStringrepresentation of a JSON object.abstract AlgorithmgetAlgorithm()Gets the Algorithm set in the JWT header.protected StringgetAlgorithmString()Gets the string representation of the Algorithm set in the JWT header.ObjectgetParameter(String key)Gets a header parameter for the specified key.<T> TgetParameter(String key, Class<T> clazz)Gets a header parameter for the specified key and then casts it to the specified type.Map<String,Object>getParameters()Returns this JwtHeader's parameters.JwtTypegetType()Gets the type of JWT this header represents.voidsetAlgorithm(Algorithm algorithm)Sets the algorithm used to perform cryptographic signing and/or encryption on the JWT.voidsetParameter(String key, Object value)Sets a header parameter with the specified key and value.voidsetParameters(Map<String,Object> headers)Sets header parameters using the values contained in the specified map.voidsetType(JwtType jwtType)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
-
-
-
-
Method Detail
-
setType
public void setType(JwtType jwtType)
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:
JwtType
-
getType
public JwtType getType()
Gets the type of JWT this header represents.- Returns:
- The JwtType.
-
setAlgorithm
public void setAlgorithm(Algorithm algorithm)
Sets the algorithm used to perform cryptographic signing and/or encryption on the JWT.- Parameters:
algorithm- The Algorithm.
-
getAlgorithm
public abstract Algorithm getAlgorithm()
Gets the Algorithm set in the JWT header.- Returns:
- The Algorithm.
-
getAlgorithmString
protected String getAlgorithmString()
Gets the string representation of the Algorithm set in the JWT header.- Returns:
- The algorithm as a String.
-
setParameter
public void setParameter(String key, Object value)
Sets a header parameter with the specified key and value.If the key matches one of the reserved header parameter names, then the relevant
setmethod 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
public void setParameters(Map<String,Object> headers)
Sets header parameters using the values contained in the specified map.- Parameters:
headers- The Map to use to set header parameters.- See Also:
setParameter(String, Object)
-
getParameter
public Object getParameter(String key)
Gets a header parameter for the specified key.If the key matches one of the reserved header parameter names, then the relevant
getmethod is called to get that header parameter.- Parameters:
key- The header parameter key.- Returns:
- The value stored against the header parameter key.
-
getParameter
public <T> T getParameter(String key, Class<T> clazz)
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:
getParameter(String)
-
getParameters
public Map<String,Object> getParameters()
Returns this JwtHeader's parameters.- Returns:
Mapof this JwtHeader's parameters.
-
build
public String build()
Builds the JWT's header into aStringrepresentation of a JSON object.- Returns:
- A JSON string.
-
-