Search in sources :

Example 31 with WSS4JAttachment

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

the class MockMessages method createErrorMessageSigned.

@Nonnull
public static Document createErrorMessageSigned(@Nonnull final ESoapVersion eSOAPVersion, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nonnull final AS4ResourceHelper aResMgr) throws WSSecurityException {
    final ICommonsList<Ebms3Error> aEbms3ErrorList = new CommonsArrayList<>(EEbmsError.EBMS_INVALID_HEADER.getAsEbms3Error(Locale.US, null));
    final AS4ErrorMessage aErrorMsg = AS4ErrorMessage.create(eSOAPVersion, "srcmsgid", aEbms3ErrorList).setMustUnderstand(true);
    return AS4Signer.createSignedMessage(AS4CryptoFactoryProperties.getDefaultInstance(), aErrorMsg.getAsSoapDocument(), eSOAPVersion, aErrorMsg.getMessagingID(), aAttachments, aResMgr, false, AS4SigningParams.createDefault());
}
Also used : Ebms3Error(com.helger.phase4.ebms3header.Ebms3Error) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) AS4ErrorMessage(com.helger.phase4.messaging.domain.AS4ErrorMessage) Nonnull(javax.annotation.Nonnull)

Example 32 with WSS4JAttachment

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

the class UserMessageCompressionTest method testUserMessageCompressedEncrpytedSuccessful.

@Test
public void testUserMessageCompressedEncrpytedSuccessful() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr));
    final Document aDoc = MockMessages.createUserMessageNotSigned(m_eSOAPVersion, null, aAttachments).getAsSoapDocument();
    final AS4MimeMessage aMsg = AS4Encryptor.encryptMimeMessage(m_eSOAPVersion, aDoc, aAttachments, m_aCryptoFactory, false, s_aResMgr, m_aCryptParams);
    sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
}
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)

Example 33 with WSS4JAttachment

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

the class UserMessageFailureForgeryTest method testUserMessageWithOnlyAttachmentsNoPartInfo.

@Test
public void testUserMessageWithOnlyAttachmentsNoPartInfo() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    final Document aSoapDoc = MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments).getAsSoapDocument();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_XML_GZ)).mimeType(CMimeType.APPLICATION_GZIP).build(), s_aResMgr));
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aSoapDoc, aAttachments);
    aMimeMsg.saveChanges();
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getErrorCode());
}
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)

Example 34 with WSS4JAttachment

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

the class UserMessageFailureForgeryTest method testPayloadChangedAfterSigningShouldFail.

@Test
public void testPayloadChangedAfterSigningShouldFail() 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 NodeList nList = aDoc.getElementsByTagName(m_eSoapVersion.getNamespacePrefix() + ":Body");
    for (int i = 0; i < nList.getLength(); i++) {
        final Node nNode = nList.item(i);
        final Element eElement = (Element) nNode;
        eElement.setAttribute("INVALID", "INVALID");
    }
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_FAILED_DECRYPTION.getErrorCode());
}
Also used : Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) 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 35 with WSS4JAttachment

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

the class UserMessageManyAttachmentTest method testUserMessageManyAttachmentsSignedMimeSuccess.

@Test
public void testUserMessageManyAttachmentsSignedMimeSuccess() throws WSSecurityException, 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));
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)).mimeType(CMimeType.IMAGE_JPG).build(), s_aResMgr));
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML2_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)

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