Class JWSObjectJSON

  • All Implemented Interfaces:
    java.io.Serializable

    @ThreadSafe
    public class JWSObjectJSON
    extends JOSEObjectJSON
    JSON Web Signature (JWS) secured object serialisable to JSON.

    This class is thread-safe.

    Version:
    2021-10-09
    Author:
    Alexander Martynov, Vladimir Dzhuvinov
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JWSObjectJSON.Signature
      Individual signature in a JWS secured object serialisable to JSON.
      static class  JWSObjectJSON.State
      Enumeration of the states of a JSON Web Signature (JWS) secured object serialisable to JSON.
    • Constructor Summary

      Constructors 
      Constructor Description
      JWSObjectJSON​(Payload payload)
      Creates a new to-be-signed JSON Web Signature (JWS) secured object with the specified payload.
    • Constructor Detail

      • JWSObjectJSON

        public JWSObjectJSON​(Payload payload)
        Creates a new to-be-signed JSON Web Signature (JWS) secured object with the specified payload.
        Parameters:
        payload - The payload. Must not be null.
    • Method Detail

      • getSignatures

        public java.util.List<JWSObjectJSON.Signature> getSignatures()
        Returns the individual signatures.
        Returns:
        The individual signatures, as an unmodified list, empty list if none have been added.
      • sign

        public void sign​(JWSHeader jwsHeader,
                         JWSSigner signer)
                  throws JOSEException
        Signs this JWS secured object with the specified JWS signer and adds the resulting signature to it. To add multiple signatures call this method successively.
        Parameters:
        jwsHeader - The JWS protected header. The algorithm specified by the header must be supported by the JWS signer. Must not be null.
        signer - The JWS signer. Must not be null.
        Throws:
        JOSEException - If the JWS object couldn't be signed.
      • sign

        public void sign​(JWSHeader jwsHeader,
                         UnprotectedHeader unprotectedHeader,
                         JWSSigner signer)
                  throws JOSEException
        Signs this JWS secured object with the specified JWS signer and adds the resulting signature to it. To add multiple signatures call this method successively.
        Parameters:
        jwsHeader - The JWS protected header. The algorithm specified by the header must be supported by the JWS signer. Must not be null.
        unprotectedHeader - The unprotected header to include, null if none.
        signer - The JWS signer. Must not be null.
        Throws:
        JOSEException - If the JWS object couldn't be signed.
      • getState

        public JWSObjectJSON.State getState()
        Returns the current signatures state.
        Returns:
        The state.
      • toGeneralJSONObject

        public java.util.Map<java.lang.String,​java.lang.Object> toGeneralJSONObject()
      • toFlattenedJSONObject

        public java.util.Map<java.lang.String,​java.lang.Object> toFlattenedJSONObject()
      • parse

        public static JWSObjectJSON parse​(java.util.Map<java.lang.String,​java.lang.Object> jsonObject)
                                   throws java.text.ParseException
        Parses a JWS secured object from the specified JSON object representation.
        Parameters:
        jsonObject - The JSON object to parse. Must not be null.
        Returns:
        The JWS secured object.
        Throws:
        java.text.ParseException - If the JSON object couldn't be parsed to a JWS secured object.
      • parse

        public static JWSObjectJSON parse​(java.lang.String json)
                                   throws java.text.ParseException
        Parses a JWS secured object from the specified JSON object string.
        Parameters:
        json - The JSON object string to parse. Must not be null.
        Returns:
        The JWS secured object.
        Throws:
        java.text.ParseException - If the string couldn't be parsed to a JWS secured object.