Search in sources :

Example 16 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity in project phase4 by phax.

the class UserMessageFailureForgeryTest method testUserMessageWrongSigningDigestAlgorithm.

@Test
public void testUserMessageWrongSigningDigestAlgorithm() throws Exception {
    final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    // never forget this!
    domFactory.setNamespaceAware(true);
    final DocumentBuilder builder = domFactory.newDocumentBuilder();
    final Document aDoc = builder.parse(new ClassPathResource("testfiles/WrongSigningDigestAlgorithm.xml").getInputStream());
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_FAILED_AUTHENTICATION.getErrorCode());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 17 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity 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 18 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity in project phase4 by phax.

the class UserMessageFailureForgeryTest method testUserMessageNoSOAPBodyPayloadNoAttachmentSignedSuccess.

// Tinkering with the signature
@Test
public void testUserMessageNoSOAPBodyPayloadNoAttachmentSignedSuccess() throws Exception {
    final Document aDoc = MockMessages.createUserMessageSigned(m_eSoapVersion, null, null, s_aResMgr);
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), true, null);
}
Also used : HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 19 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity in project phase4 by phax.

the class UserMessageFailureForgeryTest method testUserMessageWithBodyPayloadOnlyNoInfo.

@Test
public void testUserMessageWithBodyPayloadOnlyNoInfo() throws Exception {
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final Document aDoc = MockMessages.createUserMessageNotSigned(m_eSoapVersion, aPayload, null).getAsSoapDocument(aPayload);
    // Delete the added Payload in the soap body to confirm right behaviour when
    // the payload is missing
    Element aNext = XMLHelper.getFirstChildElementOfName(aDoc, "Envelope");
    aNext = XMLHelper.getFirstChildElementOfName(aNext, "Header");
    aNext = XMLHelper.getFirstChildElementOfName(aNext, CAS4.EBMS_NS, "Messaging");
    aNext = XMLHelper.getFirstChildElementOfName(aNext, CAS4.EBMS_NS, AS4TestConstants.USERMESSAGE_ASSERTCHECK);
    aNext = XMLHelper.getFirstChildElementOfName(aNext, CAS4.EBMS_NS, "PayloadInfo");
    aNext.getParentNode().removeChild(aNext);
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 20 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity in project phase4 by phax.

the class UserMessageFailureForgeryTest method testUserMessageWrongSigningAlgorithm.

@Test
public void testUserMessageWrongSigningAlgorithm() throws Exception {
    final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    // never forget this!
    domFactory.setNamespaceAware(true);
    final DocumentBuilder builder = domFactory.newDocumentBuilder();
    final Document aDoc = builder.parse(new ClassPathResource("testfiles/WrongSigningAlgorithm.xml").getInputStream());
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_FAILED_AUTHENTICATION.getErrorCode());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Aggregations

HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)65 Document (org.w3c.dom.Document)61 Test (org.junit.Test)60 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)30 Node (org.w3c.dom.Node)18 HttpEntity (org.apache.http.HttpEntity)16 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)10 NodeList (org.w3c.dom.NodeList)10 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)9 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)8 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)7 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)7 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)7 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)7 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)6 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)5 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)5 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)4