com.nimbusds.jose
Class JWSObject

java.lang.Object
  extended by com.nimbusds.jose.JOSEObject
      extended by com.nimbusds.jose.JWSObject
Direct Known Subclasses:
SignedJWT

@ThreadSafe
public class JWSObject
extends JOSEObject

JSON Web Signature (JWS) object. This class is thread-safe.

Version:
$version$ (2013-05-16)
Author:
Vladimir Dzhuvinov

Nested Class Summary
static class JWSObject.State
          Enumeration of the states of a JSON Web Signature (JWS) object.
 
Field Summary
static javax.mail.internet.ContentType MIME_TYPE_COMPACT
          The MIME type of JWS objects serialised to a compact form: application/jws; charset=UTF-8
static javax.mail.internet.ContentType MIME_TYPE_JS
          The MIME type of JWS objects serialised to a JSON object form: application/jws-js; charset=UTF-8
 
Constructor Summary
JWSObject(Base64URL firstPart, Base64URL secondPart, Base64URL thirdPart)
          Creates a new signed JSON Web Signature (JWS) object with the specified serialised parts.
JWSObject(JWSHeader header, Payload payload)
          Creates a new to-be-signed JSON Web Signature (JWS) object with the specified header and payload.
 
Method Summary
 ReadOnlyJWSHeader getHeader()
          Gets the header of this JOSE object.
 byte[] getSignableContent()
          Deprecated. Use getSigningInput() instead.
 Base64URL getSignature()
          Gets the signature of this JWS object.
 byte[] getSigningInput()
          Gets the signing input for this JWS object.
 JWSObject.State getState()
          Gets the state of this JWS object.
static JWSObject parse(String s)
          Parses a JWS object from the specified string in compact format.
 String serialize()
          Serialises this JWS object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters.
 void sign(JWSSigner signer)
          Signs this JWS object with the specified signer.
 boolean verify(JWSVerifier verifier)
          Checks the signature of this JWS object with the specified verifier.
 
Methods inherited from class com.nimbusds.jose.JOSEObject
getParsedParts, getParsedString, getPayload, setParsedParts, setPayload, split
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIME_TYPE_COMPACT

public static final javax.mail.internet.ContentType MIME_TYPE_COMPACT
The MIME type of JWS objects serialised to a compact form: application/jws; charset=UTF-8


MIME_TYPE_JS

public static final javax.mail.internet.ContentType MIME_TYPE_JS
The MIME type of JWS objects serialised to a JSON object form: application/jws-js; charset=UTF-8

Constructor Detail

JWSObject

public JWSObject(JWSHeader header,
                 Payload payload)
Creates a new to-be-signed JSON Web Signature (JWS) object with the specified header and payload. The initial state will be unsigned.

Parameters:
header - The JWS header. Must not be null.
payload - The payload. Must not be null.

JWSObject

public JWSObject(Base64URL firstPart,
                 Base64URL secondPart,
                 Base64URL thirdPart)
          throws ParseException
Creates a new signed JSON Web Signature (JWS) object with the specified serialised parts. The state will be signed.

Parameters:
firstPart - The first part, corresponding to the JWS header. Must not be null.
secondPart - The second part, corresponding to the payload. Must not be null.
thirdPart - The third part, corresponding to the signature. Must not be null.
Throws:
ParseException - If parsing of the serialised parts failed.
Method Detail

getHeader

public ReadOnlyJWSHeader getHeader()
Description copied from class: JOSEObject
Gets the header of this JOSE object.

Specified by:
getHeader in class JOSEObject
Returns:
The header.

getSigningInput

public byte[] getSigningInput()
Gets the signing input for this JWS object.

Format:

 [header-base64url].[payload-base64url]
 

Returns:
The signing input, to be passed to a JWS signer or verifier.

getSignableContent

@Deprecated
public byte[] getSignableContent()
Deprecated. Use getSigningInput() instead.


getSignature

public Base64URL getSignature()
Gets the signature of this JWS object.

Returns:
The signature, null if the JWS object is not signed yet.

getState

public JWSObject.State getState()
Gets the state of this JWS object.

Returns:
The state.

sign

public void sign(JWSSigner signer)
          throws JOSEException
Signs this JWS object with the specified signer. The JWS object must be in a unsigned state.

Parameters:
signer - The JWS signer. Must not be null.
Throws:
IllegalStateException - If the JWS object is not in an unsigned state.
JOSEException - If the JWS object couldn't be signed.

verify

public boolean verify(JWSVerifier verifier)
               throws JOSEException
Checks the signature of this JWS object with the specified verifier. The JWS object must be in a signed state.

Parameters:
verifier - The JWS verifier. Must not be null.
Returns:
true if the signature was successfully verified, else false.
Throws:
IllegalStateException - If the JWS object is not in a signed or verified state.
JOSEException - If the JWS object couldn't be verified.

serialize

public String serialize()
Serialises this JWS object to its compact format consisting of Base64URL-encoded parts delimited by period ('.') characters. It must be in a signed or verified state.
 [header-base64url].[payload-base64url].[signature-base64url]
 

Specified by:
serialize in class JOSEObject
Returns:
The serialised JWS object.
Throws:
IllegalStateException - If the JWS object is not in a signed or verified state.

parse

public static JWSObject parse(String s)
                       throws ParseException
Parses a JWS object from the specified string in compact format. The parsed JWS object will be given a JWSObject.State.SIGNED state.

Parameters:
s - The string to parse. Must not be null.
Returns:
The JWS object.
Throws:
ParseException - If the string couldn't be parsed to a valid JWS object.


Copyright © 2013 NimbusDS. All Rights Reserved.