Search in sources :

Example 61 with WSS4JAttachment

use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.

the class UserMessageOneAttachmentTest method testUserMessageOneAttachmentSignedMimeSuccess.

@Test
public void testUserMessageOneAttachmentSignedMimeSuccess() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().build(), s_aResMgr));
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments);
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSOAPVersion, AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(), m_eSOAPVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault()), aAttachments);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT.getAlgorithmURI()));
    assertTrue(sResponse.contains(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT.getAlgorithmURI()));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 62 with WSS4JAttachment

use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.

the class UserMessageSoapBodyPayloadTest method testUserMessageSOAPBodyPayloadSignedSuccess.

@Test
public void testUserMessageSOAPBodyPayloadSignedSuccess() throws Exception {
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    final Document aDoc = MockMessages.createUserMessageSigned(m_eSoapVersion, aPayload, aAttachments, s_aResMgr);
    final String sResponse = sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
    assertTrue(sResponse.contains(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT.getAlgorithmURI()));
    assertTrue(sResponse.contains(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT.getAlgorithmURI()));
}
Also used : Node(org.w3c.dom.Node) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 63 with WSS4JAttachment

use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.

the class UserMessageSoapBodyPayloadTest method testUserMessageSOAPBodyPayloadSignedEncryptedSuccess.

@Test
public void testUserMessageSOAPBodyPayloadSignedEncryptedSuccess() throws Exception {
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    Document aDoc = MockMessages.createUserMessageSigned(m_eSoapVersion, aPayload, aAttachments, s_aResMgr);
    aDoc = AS4Encryptor.encryptSoapBodyPayload(m_aCryptoFactory, m_eSoapVersion, aDoc, false, m_aCryptParams);
    final String sResponse = sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
    assertTrue(sResponse.contains(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT.getAlgorithmURI()));
    assertTrue(sResponse.contains(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT.getAlgorithmURI()));
}
Also used : Node(org.w3c.dom.Node) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 64 with WSS4JAttachment

use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.

the class AbstractUserMessageTestSetUpExt method modifyUserMessage.

/**
 * Modify the standard user message to try special cases or provoke failure
 * messages.
 *
 * @param sAnotherOrWrongPModeID
 * @param sAnotherOrWrongPartyIdInitiator
 * @param sAnotherOrWrongPartyIdResponder
 * @param aEbms3MessageProperties
 *        Default should be with _defaultProperties(), only if you do not want
 *        them change this
 * @return
 * @throws Exception
 */
@Nonnull
protected static final Document modifyUserMessage(@Nullable final String sAnotherOrWrongPModeID, @Nullable final String sAnotherOrWrongPartyIdInitiator, @Nullable final String sAnotherOrWrongPartyIdResponder, @Nullable final Ebms3MessageProperties aEbms3MessageProperties, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nullable final String sReferenceToMessageID, @Nullable final Consumer<String> aMessagingIDConsumer) throws Exception {
    // If argument is set replace the default one
    final String sSetPartyIDInitiator = sAnotherOrWrongPartyIdInitiator == null ? DEFAULT_PARTY_ID : sAnotherOrWrongPartyIdInitiator;
    final String sSetPartyIDResponder = sAnotherOrWrongPartyIdResponder == null ? DEFAULT_PARTY_ID : sAnotherOrWrongPartyIdResponder;
    Ebms3PayloadInfo aEbms3PayloadInfo;
    Node aPayload = null;
    if (aAttachments == null) {
        aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
        aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, null);
    } else {
        aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(false, aAttachments);
    }
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sReferenceToMessageID);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sAnotherOrWrongPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, sSetPartyIDInitiator, CAS4.DEFAULT_RESPONDER_URL, sSetPartyIDResponder);
    final AS4UserMessage aMsg = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, ESoapVersion.AS4_DEFAULT).setMustUnderstand(true);
    if (aMessagingIDConsumer != null)
        aMessagingIDConsumer.accept(aMsg.getMessagingID());
    return aAttachments != null ? aMsg.getAsSoapDocument(null) : aMsg.getAsSoapDocument(aPayload);
}
Also used : Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Node(org.w3c.dom.Node) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Nonnull(javax.annotation.Nonnull)

Example 65 with WSS4JAttachment

use of com.helger.phase4.attachment.WSS4JAttachment in project phase4 by phax.

the class TwoWayMEPTest method testReceiveUserMessageWithMimeAsResponseSuccess.

@Test
public void testReceiveUserMessageWithMimeAsResponseSuccess() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().build(), s_aResMgr));
    final Document aDoc = modifyUserMessage(m_aPMode.getID(), (String) null, // Alias for encryption
    "ph-as4", createDefaultProperties(), aAttachments, null, null);
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aDoc, aAttachments);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.USERMESSAGE_ASSERTCHECK));
    assertFalse(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(m_aPMode.getLeg2().getSecurity().getX509SignatureAlgorithm().getAlgorithmURI()));
    // Checking if he adds the attachment to the response message, the mock spi
    // just adds the xml that gets sent in the original message and adds it to
    // the response
    assertTrue(sResponse.contains(m_aPMode.getLeg2().getSecurity().getX509EncryptionAlgorithm().getAlgorithmURI()));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Aggregations

WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)57 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)56 Test (org.junit.Test)44 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)39 HttpMimeMessageEntity (com.helger.phase4.http.HttpMimeMessageEntity)36 Document (org.w3c.dom.Document)36 Nonnull (javax.annotation.Nonnull)29 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)23 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)15 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)13 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)13 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)13 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)12 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)11 IOException (java.io.IOException)11 Node (org.w3c.dom.Node)11 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)9 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)7 Phase4Exception (com.helger.phase4.util.Phase4Exception)7 MessagingException (javax.mail.MessagingException)7