Class TestCSMessageParser

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CSMessageResponseData genCSFailureResponse​(java.lang.String relatedEndEntity, byte[] request, RequestStatus status, java.lang.String failureMessage, java.lang.String destinationID, Credential originator)
      Method to generate a failure message response to a given request.
      CSMessage genCSMessage​(java.lang.String version, java.lang.String payLoadVersion, java.lang.String requestName, java.lang.String messageId, java.lang.String destinationID, java.lang.String organisation, Credential originator, java.lang.Object payload, java.util.List<java.lang.Object> assertions)
      Method that populates all fields except the signature of a CS message.
      byte[] generateCSRequestMessage​(java.lang.String requestId, java.lang.String destinationId, java.lang.String organisation, java.lang.String payLoadVersion, java.lang.Object payload, java.util.List<java.lang.Object> assertions)
      Method used to generate a CS Request message without any originator, i.e the signer of this message is the originator.
      byte[] generateCSRequestMessage​(java.lang.String requestId, java.lang.String destinationId, java.lang.String organisation, java.lang.String payLoadVersion, java.lang.Object payload, Credential originator, java.util.List<java.lang.Object> assertions)
      Method used to generate a CS Request message with any originator, used with relying a request message from another system.
      CSMessageResponseData generateCSResponseMessage​(java.lang.String relatedEndEntity, CSMessage request, java.lang.String payLoadVersion, java.lang.Object payload)
      Method to generate a CS Respone message from a request.
      CSMessageResponseData generateCSResponseMessage​(java.lang.String relatedEndEntity, CSMessage request, java.lang.String payLoadVersion, java.lang.Object payload, boolean isForwarable)
      Method to generate a CS Respone message from a request.
      byte[] generateGetApprovalRequest​(java.lang.String requestId, java.lang.String destinationId, java.lang.String organisation, byte[] request, Credential originator, java.util.List<java.lang.Object> assertions)
      Method generate a Get Approval Request,
      CSMessageResponseData generateGetApprovalResponse​(java.lang.String relatedEndEntity, CSMessage request, java.lang.String approvalId, ApprovalStatus approvalStatus, java.util.List<java.lang.Object> assertions)
      Method generate a Get Approved Response,
      byte[] generateIsApprovedRequest​(java.lang.String requestId, java.lang.String destinationId, java.lang.String organisation, java.lang.String approvalId, Credential originator, java.util.List<java.lang.Object> assertions)
      Method generate a Is Approved Request,
      CSMessageResponseData generateIsApprovedResponse​(java.lang.String relatedEndEntity, CSMessage request, ApprovalStatus approvalStatus, java.util.List<java.lang.Object> assertions)
      Method generate a Is Approved Response,
      javax.xml.bind.Marshaller getMarshaller​(CSMessage message)
      Method that fetches the related marshaller for a given message.
      MessageSecurityProvider getMessageSecurityProvider()
      Help method to return the related message security provider.
      Credential getOriginatorFromRequest​(CSMessage request)
      Method to extract the originator credential from a message.
      java.security.cert.X509Certificate getSigningCertificate​(byte[] request)
      Fetches the signing certificate from the request.
      CSMessageVersion getVersionFromMessage​(byte[] messageData)
      Method that tries to parse the xml version from a message
      void init​(MessageSecurityProvider securityProvider, java.util.Properties config)
      Method that initializes the CSMessage parser with a security provider and properties.
      byte[] marshallAndSignCSMessage​(CSMessage csMessage)
      Method that generates the signature and marshalls the message to byte array in UTF-8 format.
      byte[] marshallCSMessage​(CSMessage csMessage)
      Method that marshalls the message to byte array in UTF-8 format without adding any signature.
      CSMessage parseMessage​(byte[] messageData)
      Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.
      CSMessage parseMessage​(byte[] messageData, boolean performValidation)
      Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.
      CSMessage parseMessage​(byte[] messageData, boolean performValidation, boolean requireSignature)
      Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.
      CSMessage parseMessage​(org.w3c.dom.Document doc)
      Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.
      CSMessage parseMessage​(org.w3c.dom.Document doc, boolean performValidation)
      Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.
      CSMessage parseMessage​(org.w3c.dom.Document doc, boolean performValidation, boolean requireSignature)
      Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.
      byte[] populateOriginatorAssertionsAndSignCSMessage​(CSMessage message, java.lang.String destinationId, Credential originator, java.util.List<java.lang.Object> assertions)
      Method to add an originator and assertions to a CSMessage and add a signature.
      void validatePayloadObject​(CSMessageVersion version, java.lang.Object payLoadObject)
      Method to validate a payload object separately, used for special cases such when validating GetApprovalRequest requestData etc.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TestCSMessageParser

        public TestCSMessageParser()
    • Method Detail

      • generateCSRequestMessage

        public byte[] generateCSRequestMessage​(java.lang.String requestId,
                                               java.lang.String destinationId,
                                               java.lang.String organisation,
                                               java.lang.String payLoadVersion,
                                               java.lang.Object payload,
                                               java.util.List<java.lang.Object> assertions)
                                        throws MessageContentException,
                                               MessageProcessingException
        Description copied from interface: CSMessageParser
        Method used to generate a CS Request message without any originator, i.e the signer of this message is the originator.
        Specified by:
        generateCSRequestMessage in interface CSMessageParser
        Parameters:
        requestId - id of request to send.
        destinationId - the destination Id to use.
        organisation - the related organisation (short name)
        payLoadVersion - version of the pay load structure.
        payload - the pay load object
        assertions - a list of authorization assertions or null if no assertions should be inserted.
        Returns:
        a generated and signed (if configured) message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • generateCSRequestMessage

        public byte[] generateCSRequestMessage​(java.lang.String requestId,
                                               java.lang.String destinationId,
                                               java.lang.String organisation,
                                               java.lang.String payLoadVersion,
                                               java.lang.Object payload,
                                               Credential originator,
                                               java.util.List<java.lang.Object> assertions)
                                        throws MessageContentException,
                                               MessageProcessingException
        Description copied from interface: CSMessageParser
        Method used to generate a CS Request message with any originator, used with relying a request message from another system.
        Specified by:
        generateCSRequestMessage in interface CSMessageParser
        Parameters:
        requestId - id of request to send.
        destinationId - the destination Id to use.
        organisation - the related organisation (short name)
        payLoadVersion - version of the pay load structure.
        payload - the payload object
        originator - the credential of the original requester.
        assertions - a list of authorization assertions or null if no assertions should be inserted.
        Returns:
        a generated and signed (if configured) message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • generateCSResponseMessage

        public CSMessageResponseData generateCSResponseMessage​(java.lang.String relatedEndEntity,
                                                               CSMessage request,
                                                               java.lang.String payLoadVersion,
                                                               java.lang.Object payload)
                                                        throws MessageContentException,
                                                               MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to generate a CS Respone message from a request. CS Response message will be marked as non forwardable, which means not for use in data syncronization applications.
        Specified by:
        generateCSResponseMessage in interface CSMessageParser
        Parameters:
        relatedEndEntity - the name of the related end entity (such as username of the related user)
        request - the related request
        payLoadVersion - version of the pay load structure.
        payload - the payload object
        Returns:
        a generated and signed (if configured) message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • generateCSResponseMessage

        public CSMessageResponseData generateCSResponseMessage​(java.lang.String relatedEndEntity,
                                                               CSMessage request,
                                                               java.lang.String payLoadVersion,
                                                               java.lang.Object payload,
                                                               boolean isForwarable)
                                                        throws MessageContentException,
                                                               MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to generate a CS Respone message from a request.
        Specified by:
        generateCSResponseMessage in interface CSMessageParser
        Parameters:
        relatedEndEntity - the name of the related end entity (such as username of the related user)
        request - the related request
        payLoadVersion - version of the pay load structure.
        payload - the payload object
        isForwarable - if message will be marked as non forwardable, i.e. for use in data syncronization applications.
        Returns:
        a generated and signed (if configured) message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • generateGetApprovalRequest

        public byte[] generateGetApprovalRequest​(java.lang.String requestId,
                                                 java.lang.String destinationId,
                                                 java.lang.String organisation,
                                                 byte[] request,
                                                 Credential originator,
                                                 java.util.List<java.lang.Object> assertions)
                                          throws MessageContentException,
                                                 MessageProcessingException
        Description copied from interface: CSMessageParser
        Method generate a Get Approval Request,
        Specified by:
        generateGetApprovalRequest in interface CSMessageParser
        Parameters:
        requestId - id of request to send.
        destinationId - the destination Id to use.
        organisation - the related organisation (short name)
        request - the request message to get approval for.
        originator - the credential of the original requester, null if this is the origin of the request.
        assertions - a list of related authorization assertions, or null if no authorization assertions is available.
        Returns:
        a generated and signed (if configured) message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • generateIsApprovedRequest

        public byte[] generateIsApprovedRequest​(java.lang.String requestId,
                                                java.lang.String destinationId,
                                                java.lang.String organisation,
                                                java.lang.String approvalId,
                                                Credential originator,
                                                java.util.List<java.lang.Object> assertions)
                                         throws MessageContentException,
                                                MessageProcessingException
        Description copied from interface: CSMessageParser
        Method generate a Is Approved Request,
        Specified by:
        generateIsApprovedRequest in interface CSMessageParser
        Parameters:
        requestId - id of request to send.
        destinationId - the destination Id to use.
        organisation - the related organisation (short name)
        approvalId - the approval id to check.
        originator - the credential of the original requester, null if this is the origin of the request.
        assertions - a list of related authorization assertions, or null if no authorization assertions is available.
        Returns:
        a generated and signed (if configured) message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • generateGetApprovalResponse

        public CSMessageResponseData generateGetApprovalResponse​(java.lang.String relatedEndEntity,
                                                                 CSMessage request,
                                                                 java.lang.String approvalId,
                                                                 ApprovalStatus approvalStatus,
                                                                 java.util.List<java.lang.Object> assertions)
                                                          throws MessageContentException,
                                                                 MessageProcessingException
        Description copied from interface: CSMessageParser
        Method generate a Get Approved Response,
        Specified by:
        generateGetApprovalResponse in interface CSMessageParser
        Parameters:
        relatedEndEntity - the user name of related user in system.
        request - the request data.
        approvalId - the approval id that was generated for the request
        approvalStatus - the approval status
        assertions - a list of related authorization assertions, or null if no authorization assertions is available.
        Returns:
        a generated and signed (if configured) message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • populateOriginatorAssertionsAndSignCSMessage

        public byte[] populateOriginatorAssertionsAndSignCSMessage​(CSMessage message,
                                                                   java.lang.String destinationId,
                                                                   Credential originator,
                                                                   java.util.List<java.lang.Object> assertions)
                                                            throws MessageContentException,
                                                                   MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to add an originator and assertions to a CSMessage and add a signature. If signature exists it is removed.
        Specified by:
        populateOriginatorAssertionsAndSignCSMessage in interface CSMessageParser
        Parameters:
        message - the message to populate.
        destinationId - the updated destination, null for unchanged.
        originator - the originator to add, null for no originator
        assertions - the assertions to add, null for no assertions.
        Returns:
        a populated and signed CSMessage.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • genCSFailureResponse

        public CSMessageResponseData genCSFailureResponse​(java.lang.String relatedEndEntity,
                                                          byte[] request,
                                                          RequestStatus status,
                                                          java.lang.String failureMessage,
                                                          java.lang.String destinationID,
                                                          Credential originator)
                                                   throws MessageContentException,
                                                          MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to generate a failure message response to a given request.
        Specified by:
        genCSFailureResponse in interface CSMessageParser
        Parameters:
        relatedEndEntity - the user name of related user in system.
        request - the request data.
        status - the request status of the response
        failureMessage - a readable failure message.
        destinationID - the destination id of the message. If null will destination id be extracted from request data.
        originator - originator of the request, null if no originator could be found.
        Returns:
        Throws:
        MessageProcessingException - if internal error occurred parsing the certificate.
        MessageContentException
      • validatePayloadObject

        public void validatePayloadObject​(CSMessageVersion version,
                                          java.lang.Object payLoadObject)
                                   throws MessageContentException
        Description copied from interface: CSMessageParser
        Method to validate a payload object separately, used for special cases such when validating GetApprovalRequest requestData etc.
        Specified by:
        validatePayloadObject in interface CSMessageParser
        Parameters:
        version - the versions of a CS message.
        payLoadObject - the pay load object to validate schema for.
        Throws:
        MessageContentException - if the message contained invalid XML.
      • parseMessage

        public CSMessage parseMessage​(byte[] messageData,
                                      boolean performValidation)
                               throws MessageContentException,
                                      MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.

        Signatures are required.

        Specified by:
        parseMessage in interface CSMessageParser
        Parameters:
        messageData - the data to parse into a CSMessage
        performValidation - true if the message security provider should perform validate that the signing certificate is valid and authorized for related organisation. Otherwise must validation be performed manually after the message is parsed.
        Returns:
        a parsed CS Message object.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • parseMessage

        public CSMessage parseMessage​(byte[] messageData,
                                      boolean performValidation,
                                      boolean requireSignature)
                               throws MessageContentException,
                                      MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.
        Specified by:
        parseMessage in interface CSMessageParser
        Parameters:
        messageData - the data to parse into a CSMessage
        performValidation - true if the message security provider should perform validate that the signing certificate is valid and authorized for related organisation. Otherwise must validation be performed manually after the message is parsed.
        requireSignature - if signature should be required.
        Returns:
        a parsed CS Message object.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • genCSMessage

        public CSMessage genCSMessage​(java.lang.String version,
                                      java.lang.String payLoadVersion,
                                      java.lang.String requestName,
                                      java.lang.String messageId,
                                      java.lang.String destinationID,
                                      java.lang.String organisation,
                                      Credential originator,
                                      java.lang.Object payload,
                                      java.util.List<java.lang.Object> assertions)
                               throws MessageContentException,
                                      MessageProcessingException
        Description copied from interface: CSMessageParser
        Method that populates all fields except the signature of a CS message.
        Specified by:
        genCSMessage in interface CSMessageParser
        Parameters:
        version - , version of the CS Message
        payLoadVersion - , version of the pay load structure.
        requestName - the name in the a related request if this is a response message, or null if no related request exists
        messageId - the id of the message, if null is a random id generated.
        destinationID - the destination Id to use.
        organisation - the related organisation
        originator - the originator of the message if applicable.
        payload - the payload object to set in the object
        assertions - a list of authorization assertions used along with this message.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • getOriginatorFromRequest

        public Credential getOriginatorFromRequest​(CSMessage request)
        Description copied from interface: CSMessageParser
        Method to extract the originator credential from a message.
        Specified by:
        getOriginatorFromRequest in interface CSMessageParser
        Parameters:
        request - the request message to extract the originator from.
        Returns:
        the originator credential from the message or null if no originator was found.
      • parseMessage

        public CSMessage parseMessage​(org.w3c.dom.Document doc,
                                      boolean performValidation)
                               throws MessageContentException,
                                      MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.

        Signatures are required.

        Specified by:
        parseMessage in interface CSMessageParser
        Parameters:
        doc - The Document data to parse into a CSMessage
        performValidation - true if the message security provider should perform validate that the signing certificate is valid and authorized for related organisation. Otherwise must validation be performed manually after the message is parsed.
        Returns:
        a parsed CS Message object.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.
      • parseMessage

        public CSMessage parseMessage​(org.w3c.dom.Document doc,
                                      boolean performValidation,
                                      boolean requireSignature)
                               throws MessageContentException,
                                      MessageProcessingException
        Description copied from interface: CSMessageParser
        Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.

        Signatures are required.

        Specified by:
        parseMessage in interface CSMessageParser
        Parameters:
        doc - The Document data to parse into a CSMessage
        performValidation - true if the message security provider should perform validate that the signing certificate is valid and authorized for related organisation. Otherwise must validation be performed manually after the message is parsed.
        requireSignature - if signature should be required.
        Returns:
        a parsed CS Message object.
        Throws:
        MessageContentException - if input data contained invalid format.
        MessageProcessingException - if internal problems occurred processing the cs message.