Class TestCSMessageParser
- java.lang.Object
-
- org.certificateservices.messages.csmessages.TestCSMessageParser
-
- All Implemented Interfaces:
CSMessageParser
public class TestCSMessageParser extends java.lang.Object implements CSMessageParser
-
-
Constructor Summary
Constructors Constructor Description TestCSMessageParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CSMessageResponseDatagenCSFailureResponse(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.CSMessagegenCSMessage(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.CSMessageResponseDatagenerateCSResponseMessage(java.lang.String relatedEndEntity, CSMessage request, java.lang.String payLoadVersion, java.lang.Object payload)Method to generate a CS Respone message from a request.CSMessageResponseDatagenerateCSResponseMessage(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,CSMessageResponseDatagenerateGetApprovalResponse(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,CSMessageResponseDatagenerateIsApprovedResponse(java.lang.String relatedEndEntity, CSMessage request, ApprovalStatus approvalStatus, java.util.List<java.lang.Object> assertions)Method generate a Is Approved Response,javax.xml.bind.MarshallergetMarshaller(CSMessage message)Method that fetches the related marshaller for a given message.MessageSecurityProvidergetMessageSecurityProvider()Help method to return the related message security provider.CredentialgetOriginatorFromRequest(CSMessage request)Method to extract the originator credential from a message.java.security.cert.X509CertificategetSigningCertificate(byte[] request)Fetches the signing certificate from the request.CSMessageVersiongetVersionFromMessage(byte[] messageData)Method that tries to parse the xml version from a messagevoidinit(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.CSMessageparseMessage(byte[] messageData)Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.CSMessageparseMessage(byte[] messageData, boolean performValidation)Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.CSMessageparseMessage(byte[] messageData, boolean performValidation, boolean requireSignature)Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.CSMessageparseMessage(org.w3c.dom.Document doc)Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.CSMessageparseMessage(org.w3c.dom.Document doc, boolean performValidation)Method to parse a message into a CSMessage and verify that it fulfills the registred schemas.CSMessageparseMessage(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.voidvalidatePayloadObject(CSMessageVersion version, java.lang.Object payLoadObject)Method to validate a payload object separately, used for special cases such when validating GetApprovalRequest requestData etc.
-
-
-
Method Detail
-
init
public void init(MessageSecurityProvider securityProvider, java.util.Properties config) throws MessageProcessingException
Description copied from interface:CSMessageParserMethod that initializes the CSMessage parser with a security provider and properties.- Specified by:
initin interfaceCSMessageParser- Parameters:
securityProvider- the CSMessage security provider to use.config- the configuration of the parser.- Throws:
MessageProcessingException- if configuration contained bad configuration of security provider.
-
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, MessageProcessingExceptionDescription copied from interface:CSMessageParserMethod used to generate a CS Request message without any originator, i.e the signer of this message is the originator.- Specified by:
generateCSRequestMessagein interfaceCSMessageParser- 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 objectassertions- 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, MessageProcessingExceptionDescription copied from interface:CSMessageParserMethod used to generate a CS Request message with any originator, used with relying a request message from another system.- Specified by:
generateCSRequestMessagein interfaceCSMessageParser- 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 objectoriginator- 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:CSMessageParserMethod 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:
generateCSResponseMessagein interfaceCSMessageParser- Parameters:
relatedEndEntity- the name of the related end entity (such as username of the related user)request- the related requestpayLoadVersion- 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:CSMessageParserMethod to generate a CS Respone message from a request.- Specified by:
generateCSResponseMessagein interfaceCSMessageParser- Parameters:
relatedEndEntity- the name of the related end entity (such as username of the related user)request- the related requestpayLoadVersion- version of the pay load structure.payload- the payload objectisForwarable- 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, MessageProcessingExceptionDescription copied from interface:CSMessageParserMethod generate a Get Approval Request,- Specified by:
generateGetApprovalRequestin interfaceCSMessageParser- 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, MessageProcessingExceptionDescription copied from interface:CSMessageParserMethod generate a Is Approved Request,- Specified by:
generateIsApprovedRequestin interfaceCSMessageParser- 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.
-
generateIsApprovedResponse
public CSMessageResponseData generateIsApprovedResponse(java.lang.String relatedEndEntity, CSMessage request, ApprovalStatus approvalStatus, java.util.List<java.lang.Object> assertions) throws MessageContentException, MessageProcessingException
Description copied from interface:CSMessageParserMethod generate a Is Approved Response,- Specified by:
generateIsApprovedResponsein interfaceCSMessageParser- Parameters:
relatedEndEntity- the user name of related user in system.request- the request data.approvalStatus- the status of the related approval Id.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:CSMessageParserMethod generate a Get Approved Response,- Specified by:
generateGetApprovalResponsein interfaceCSMessageParser- Parameters:
relatedEndEntity- the user name of related user in system.request- the request data.approvalId- the approval id that was generated for the requestapprovalStatus- the approval statusassertions- 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:CSMessageParserMethod to add an originator and assertions to a CSMessage and add a signature. If signature exists it is removed.- Specified by:
populateOriginatorAssertionsAndSignCSMessagein interfaceCSMessageParser- Parameters:
message- the message to populate.destinationId- the updated destination, null for unchanged.originator- the originator to add, null for no originatorassertions- 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:CSMessageParserMethod to generate a failure message response to a given request.- Specified by:
genCSFailureResponsein interfaceCSMessageParser- Parameters:
relatedEndEntity- the user name of related user in system.request- the request data.status- the request status of the responsefailureMessage- 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
-
getSigningCertificate
public java.security.cert.X509Certificate getSigningCertificate(byte[] request) throws MessageContentException, MessageProcessingExceptionDescription copied from interface:CSMessageParserFetches the signing certificate from the request.- Specified by:
getSigningCertificatein interfaceCSMessageParser- Parameters:
request- the request to parse the certificate from.- Returns:
- the signer certificate of null if no certificate is required by the parser.
- Throws:
MessageProcessingException- if internal error occurred parsing the certificate.MessageContentException
-
marshallAndSignCSMessage
public byte[] marshallAndSignCSMessage(CSMessage csMessage) throws MessageProcessingException, MessageContentException
Description copied from interface:CSMessageParserMethod that generates the signature and marshalls the message to byte array in UTF-8 format.- Specified by:
marshallAndSignCSMessagein interfaceCSMessageParser- Parameters:
csMessage- the CSMessage to sign and marshall, never null.- Returns:
- a marshalled and signed message.
- Throws:
MessageProcessingException- if problems occurred when processing the message.MessageContentException
-
marshallCSMessage
public byte[] marshallCSMessage(CSMessage csMessage) throws MessageProcessingException, MessageContentException
Description copied from interface:CSMessageParserMethod that marshalls the message to byte array in UTF-8 format without adding any signature.- Specified by:
marshallCSMessagein interfaceCSMessageParser- Parameters:
csMessage- the CSMessage to marshall, never null.- Returns:
- a marshalled message.
- Throws:
MessageProcessingException- if problems occurred when processing the message.MessageContentException
-
validatePayloadObject
public void validatePayloadObject(CSMessageVersion version, java.lang.Object payLoadObject) throws MessageContentException
Description copied from interface:CSMessageParserMethod to validate a payload object separately, used for special cases such when validating GetApprovalRequest requestData etc.- Specified by:
validatePayloadObjectin interfaceCSMessageParser- 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.
-
getVersionFromMessage
public CSMessageVersion getVersionFromMessage(byte[] messageData) throws MessageContentException, MessageProcessingException
Description copied from interface:CSMessageParserMethod that tries to parse the xml version from a message- Specified by:
getVersionFromMessagein interfaceCSMessageParser- Parameters:
messageData- the messageData to extract version from.- Returns:
- the version in the version and payLoadVersion attributes of the message.
- Throws:
MessageContentException- didn't contains a valid version attribute.MessageProcessingException- if internal problems occurred.
-
parseMessage
public CSMessage parseMessage(byte[] messageData) throws MessageContentException, MessageProcessingException
Description copied from interface:CSMessageParserMethod to parse a message into a CSMessage and verify that it fulfills the registred schemas.This method always validates and authorizes the signing certificate.
- Specified by:
parseMessagein interfaceCSMessageParser- Parameters:
messageData- the data to parse into a CSMessage- 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) throws MessageContentException, MessageProcessingException
Description copied from interface:CSMessageParserMethod to parse a message into a CSMessage and verify that it fulfills the registred schemas.Signatures are required.
- Specified by:
parseMessagein interfaceCSMessageParser- Parameters:
messageData- the data to parse into a CSMessageperformValidation- 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:CSMessageParserMethod to parse a message into a CSMessage and verify that it fulfills the registred schemas.- Specified by:
parseMessagein interfaceCSMessageParser- Parameters:
messageData- the data to parse into a CSMessageperformValidation- 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:CSMessageParserMethod that populates all fields except the signature of a CS message.- Specified by:
genCSMessagein interfaceCSMessageParser- Parameters:
version- , version of the CS MessagepayLoadVersion- , 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 existsmessageId- the id of the message, if null is a random id generated.destinationID- the destination Id to use.organisation- the related organisationoriginator- the originator of the message if applicable.payload- the payload object to set in the objectassertions- 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:CSMessageParserMethod to extract the originator credential from a message.- Specified by:
getOriginatorFromRequestin interfaceCSMessageParser- Parameters:
request- the request message to extract the originator from.- Returns:
- the originator credential from the message or null if no originator was found.
-
getMessageSecurityProvider
public MessageSecurityProvider getMessageSecurityProvider()
Description copied from interface:CSMessageParserHelp method to return the related message security provider.- Specified by:
getMessageSecurityProviderin interfaceCSMessageParser- Returns:
- the related message security provider, never null.
-
getMarshaller
public javax.xml.bind.Marshaller getMarshaller(CSMessage message) throws MessageContentException
Description copied from interface:CSMessageParserMethod that fetches the related marshaller for a given message.- Specified by:
getMarshallerin interfaceCSMessageParser- Parameters:
message- the message to fetch related marshaller for.- Returns:
- the marshaller
- Throws:
MessageContentException- if message content was faulty or no related marshaller could be found.
-
parseMessage
public CSMessage parseMessage(org.w3c.dom.Document doc) throws MessageContentException, MessageProcessingException
Description copied from interface:CSMessageParserMethod to parse a message into a CSMessage and verify that it fulfills the registred schemas.This method always validates and authorizes the signing certificate.
- Specified by:
parseMessagein interfaceCSMessageParser- Parameters:
doc- The Document data to parse into a CSMessage- 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) throws MessageContentException, MessageProcessingException
Description copied from interface:CSMessageParserMethod to parse a message into a CSMessage and verify that it fulfills the registred schemas.Signatures are required.
- Specified by:
parseMessagein interfaceCSMessageParser- Parameters:
doc- The Document data to parse into a CSMessageperformValidation- 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:CSMessageParserMethod to parse a message into a CSMessage and verify that it fulfills the registred schemas.Signatures are required.
- Specified by:
parseMessagein interfaceCSMessageParser- Parameters:
doc- The Document data to parse into a CSMessageperformValidation- 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.
-
-