com.nimbusds.jose
Class Header

java.lang.Object
  extended by com.nimbusds.jose.Header
All Implemented Interfaces:
ReadOnlyHeader
Direct Known Subclasses:
CommonSEHeader, PlainHeader

public abstract class Header
extends java.lang.Object
implements ReadOnlyHeader

The base abstract class for plaintext, JSON Web Signature (JWS) and JSON Web Encryption (JWE) headers.

The header may also carry custom parameters; these will be serialised and parsed along the reserved ones.

Version:
$version$ (2012-12-09)
Author:
Vladimir Dzhuvinov

Field Summary
protected  Algorithm alg
          The algorithm (alg) parameter.
 
Constructor Summary
protected Header(Algorithm alg)
          Creates a new header with the specified algorithm (alg) parameter.
 
Method Summary
 java.lang.String getContentType()
          Gets the content type (cty) parameter.
 java.lang.Object getCustomParameter(java.lang.String name)
          Gets a custom (non-reserved) parameter.
 java.util.Map<java.lang.String,java.lang.Object> getCustomParameters()
          Gets the custom (non-reserved) parameters.
 JOSEObjectType getType()
          Gets the type (typ) parameter.
static Header parse(net.minidev.json.JSONObject json)
          Parses a PlainHeader, JWSHeader or JWEHeader from the specified JSON object.
static Algorithm parseAlgorithm(net.minidev.json.JSONObject json)
          Parses an algorithm (alg) parameter from the specified header JSON object.
 void setContentType(java.lang.String cty)
          Sets the content type (cty) parameter.
protected  void setCustomParameter(java.lang.String name, java.lang.Object value)
          Sets a custom (non-reserved) parameter.
 void setCustomParameters(java.util.Map<java.lang.String,java.lang.Object> customParameters)
          Sets the custom (non-reserved) parameters.
 void setType(JOSEObjectType typ)
          Sets the type (typ) parameter.
 Base64URL toBase64URL()
          Returns a Base64URL representation of the header.
 net.minidev.json.JSONObject toJSONObject()
          Returns a JSON object representation of the header.
 java.lang.String toString()
          Returns a JSON string representation of this header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.nimbusds.jose.ReadOnlyHeader
getAlgorithm, getIncludedParameters
 

Field Detail

alg

protected final Algorithm alg
The algorithm (alg) parameter.

Constructor Detail

Header

protected Header(Algorithm alg)
Creates a new header with the specified algorithm (alg) parameter.

Parameters:
alg - The algorithm parameter. Must not be null.
Method Detail

getType

public JOSEObjectType getType()
Description copied from interface: ReadOnlyHeader
Gets the type (typ) parameter.

Specified by:
getType in interface ReadOnlyHeader
Returns:
The type parameter, null if not specified.

setType

public void setType(JOSEObjectType typ)
Sets the type (typ) parameter.

Parameters:
typ - The type parameter, null if not specified.

getContentType

public java.lang.String getContentType()
Description copied from interface: ReadOnlyHeader
Gets the content type (cty) parameter.

Specified by:
getContentType in interface ReadOnlyHeader
Returns:
The content type parameter, null if not specified.

setContentType

public void setContentType(java.lang.String cty)
Sets the content type (cty) parameter.

Parameters:
cty - The content type parameter, null if not specified.

getCustomParameter

public java.lang.Object getCustomParameter(java.lang.String name)
Description copied from interface: ReadOnlyHeader
Gets a custom (non-reserved) parameter.

Specified by:
getCustomParameter in interface ReadOnlyHeader
Parameters:
name - The name of the custom parameter. Must not be null.
Returns:
The custom parameter, null if not specified.

setCustomParameter

protected void setCustomParameter(java.lang.String name,
                                  java.lang.Object value)
Sets a custom (non-reserved) parameter. Callers and extending classes should ensure the parameter name doesn't match a reserved parameter name.

Parameters:
name - The name of the custom parameter. Must not match a reserved parameter name and must not be null.
value - The value of the custom parameter, should map to a valid JSON entity, null if not specified.

getCustomParameters

public java.util.Map<java.lang.String,java.lang.Object> getCustomParameters()
Description copied from interface: ReadOnlyHeader
Gets the custom (non-reserved) parameters.

Specified by:
getCustomParameters in interface ReadOnlyHeader
Returns:
The custom parameters, as a unmodifiable map, empty map if none.

setCustomParameters

public void setCustomParameters(java.util.Map<java.lang.String,java.lang.Object> customParameters)
Sets the custom (non-reserved) parameters. The values must be serialisable to a JSON entity, otherwise will be ignored.

Parameters:
customParameters - The custom parameters, empty map or null if none.

toJSONObject

public net.minidev.json.JSONObject toJSONObject()
Description copied from interface: ReadOnlyHeader
Returns a JSON object representation of the header. All custom parameters are included if they serialise to a JSON entity and their names don't conflict with the reserved ones.

Specified by:
toJSONObject in interface ReadOnlyHeader
Returns:
The JSON object representation of the header.

toString

public java.lang.String toString()
Returns a JSON string representation of this header. All custom parameters will be included if they serialise to a JSON entity and their names don't conflict with the reserved ones.

Overrides:
toString in class java.lang.Object
Returns:
The JSON string representation of this header.

toBase64URL

public Base64URL toBase64URL()
Description copied from interface: ReadOnlyHeader
Returns a Base64URL representation of the header.

Specified by:
toBase64URL in interface ReadOnlyHeader
Returns:
The Base64URL representation of the header.

parseAlgorithm

public static Algorithm parseAlgorithm(net.minidev.json.JSONObject json)
                                throws java.text.ParseException
Parses an algorithm (alg) parameter from the specified header JSON object. Intended for initial parsing of plain, JWS and JWE headers.

The algorithm type (none, JWS or JWE) is determined by inspecting the algorithm name for "none" and the presence of an "enc" parameter.

Parameters:
json - The JSON object to parse. Must not be null.
Returns:
The algorithm, an instance of Algorithm.NONE, JWSAlgorithm or JWEAlgorithm.
Throws:
java.text.ParseException - If the alg parameter couldn't be parsed.

parse

public static Header parse(net.minidev.json.JSONObject json)
                    throws java.text.ParseException
Parses a PlainHeader, JWSHeader or JWEHeader from the specified JSON object.

Parameters:
json - The JSON object to parse. Must not be null.
Returns:
The header.
Throws:
java.text.ParseException - If the specified JSON object doesn't represent a valid header.


Copyright © 2013 NimbusDS. All Rights Reserved.