You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2015/07/06 17:57:28 UTC
svn commit: r1689436 - in
/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message:
AttachmentCallbackHandler.java XOPAttachmentTest.java
Author: coheigea
Date: Mon Jul 6 15:57:28 2015
New Revision: 1689436
URL: http://svn.apache.org/r1689436
Log:
[WSS-544] - Adding a test
Modified:
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentCallbackHandler.java
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentCallbackHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentCallbackHandler.java?rev=1689436&r1=1689435&r2=1689436&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentCallbackHandler.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentCallbackHandler.java Mon Jul 6 15:57:28 2015
@@ -29,13 +29,14 @@ import org.apache.wss4j.common.ext.Attac
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A Callback Handler implementation for the case of signing/encrypting Attachments via the SwA
- * (SOAP with Attachments) specification.
+ * (SOAP with Attachments) specification or when using xop:Include in the case of MTOM.
*/
public class AttachmentCallbackHandler implements CallbackHandler {
@@ -43,6 +44,10 @@ public class AttachmentCallbackHandler i
private Map<String, Attachment> attachmentMap = new HashMap<String, Attachment>();
private List<Attachment> responseAttachments = new ArrayList<Attachment>();
+ public AttachmentCallbackHandler() {
+ originalRequestAttachments = Collections.emptyList();
+ }
+
public AttachmentCallbackHandler(List<Attachment> attachments) {
originalRequestAttachments = attachments;
if (attachments != null) {
Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java?rev=1689436&r1=1689435&r2=1689436&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java Mon Jul 6 15:57:28 2015
@@ -47,7 +47,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
- * Test for processing an xop:Include inside a CipherValue Element
+ * Test for creating / processing an xop:Include inside a CipherValue Element
*/
public class XOPAttachmentTest extends org.junit.Assert {
@@ -84,8 +84,9 @@ public class XOPAttachmentTest extends o
// Set up a test to encrypt the SOAP Body + an attachment, which is the same content as
// the SOAP Body. Then replace the encrypted SOAP Body with a xop:Include to the attachment,
// and modify the request to remove the encryption stuff pointing to the attachment.
+ // (NOTE: This test was before we supported creating requests with xop:Include)
@org.junit.Test
- public void testEncryptedSOAPBody() throws Exception {
+ public void testManualEncryptedSOAPBody() throws Exception {
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecEncrypt encrypt = new WSSecEncrypt();
encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
@@ -171,6 +172,43 @@ public class XOPAttachmentTest extends o
String processedDoc = XMLUtils.PrettyDocumentToString(encryptedDoc);
assertTrue(processedDoc.contains(SOAP_BODY));
+ }
+
+ @org.junit.Test
+ public void testEncryptedSOAPBody() throws Exception {
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecEncrypt encrypt = new WSSecEncrypt();
+ encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ encrypt.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ AttachmentCallbackHandler outboundAttachmentCallback = new AttachmentCallbackHandler();
+ encrypt.setAttachmentCallbackHandler(outboundAttachmentCallback);
+ encrypt.setStoreBytesInAttachment(true);
+
+ encrypt.getParts().add(new WSEncryptionPart("Body", "http://schemas.xmlsoap.org/soap/envelope/", "Content"));
+
+ Document encryptedDoc = encrypt.build(doc, crypto, secHeader);
+
+ List<Attachment> encryptedAttachments = outboundAttachmentCallback.getResponseAttachments();
+ assertNotNull(encryptedAttachments);
+ // Should have EncryptedKey + EncryptedData stored in attachments...
+ assertTrue(encryptedAttachments.size() == 2);
+
+ if (LOG.isDebugEnabled()) {
+ String outputString = XMLUtils.PrettyDocumentToString(encryptedDoc);
+ LOG.debug(outputString);
+ // System.out.println(outputString);
+ }
+
+ AttachmentCallbackHandler inboundAttachmentCallback =
+ new AttachmentCallbackHandler(encryptedAttachments);
+ verify(encryptedDoc, inboundAttachmentCallback);
+
+ String processedDoc = XMLUtils.PrettyDocumentToString(encryptedDoc);
+ assertTrue(processedDoc.contains(SOAP_BODY));
}
/**