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/06/18 13:16:45 UTC

svn commit: r1686186 - /webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java

Author: coheigea
Date: Thu Jun 18 11:16:45 2015
New Revision: 1686186

URL: http://svn.apache.org/r1686186
Log:
WSS-541 Copy the attachment handing code from the sign/encrypt routines to the derived key versions


Conflicts:
	ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java

Modified:
    webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java

Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java?rev=1686186&r1=1686185&r2=1686186&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java Thu Jun 18 11:16:45 2015
@@ -19,12 +19,17 @@
 
 package org.apache.wss4j.dom.message;
 
-import org.apache.wss4j.dom.WSConstants;
-import org.apache.wss4j.dom.WSSConfig;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.crypto.SecretKey;
+
 import org.apache.wss4j.common.WSEncryptionPart;
+import org.apache.wss4j.common.derivedKey.ConversationConstants;
 import org.apache.wss4j.common.ext.WSSecurityException;
 import org.apache.wss4j.common.util.KeyUtils;
-import org.apache.wss4j.common.derivedKey.ConversationConstants;
+import org.apache.wss4j.dom.WSConstants;
+import org.apache.wss4j.dom.WSSConfig;
 import org.apache.wss4j.dom.message.token.Reference;
 import org.apache.wss4j.dom.message.token.SecurityTokenReference;
 import org.apache.wss4j.dom.util.WSSecurityUtil;
@@ -33,11 +38,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
-import javax.crypto.SecretKey;
-
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * Encrypts and signs parts of a message with derived keys derived from a
  * symmetric key. This symmetric key will be included as an EncryptedKey
@@ -45,6 +45,8 @@ import java.util.List;
 public class WSSecDKEncrypt extends WSSecDerivedKeyBase {
 
     private String symEncAlgo = WSConstants.AES_128;
+
+    private List<Element> attachmentEncryptedDataElements;
     
     public WSSecDKEncrypt() {
         super();
@@ -54,6 +56,13 @@ public class WSSecDKEncrypt extends WSSe
         super(config);
     }
     
+    @Override
+    public void prepare(Document doc) throws WSSecurityException {
+        super.prepare(doc);
+
+        attachmentEncryptedDataElements = new ArrayList<Element>();
+    }
+
     public Document build(Document doc, WSSecHeader secHeader) throws WSSecurityException {
         
         //
@@ -78,6 +87,16 @@ public class WSSecDKEncrypt extends WSSe
             parts.add(encP);
         }
         Element externRefList = encryptForExternalRef(null, parts);
+
+        if (attachmentEncryptedDataElements != null) {
+            for (int i = 0; i < attachmentEncryptedDataElements.size(); i++) {
+                Element encryptedData = attachmentEncryptedDataElements.get(i);
+                WSSecurityUtil.prependChildElement(
+                        secHeader.getSecurityHeader(), encryptedData
+                );
+            }
+        }
+
         addExternalRefElement(externRefList, secHeader);
 
         return doc;
@@ -113,7 +132,7 @@ public class WSSecDKEncrypt extends WSSe
 
         List<String> encDataRefs = 
             WSSecEncrypt.doEncryption(
-                document, getWsConfig(), keyInfo, key, symEncAlgo, references, callbackLookup
+                document, getWsConfig(), keyInfo, key, symEncAlgo, references, callbackLookup, attachmentCallbackHandler, attachmentEncryptedDataElements
             );
         if (dataRef == null) {
             dataRef = 
@@ -187,4 +206,7 @@ public class WSSecDKEncrypt extends WSSe
             KeyUtils.getKeyLength(symEncAlgo);
     }
     
+    public List<Element> getAttachmentEncryptedDataElements() {
+        return attachmentEncryptedDataElements;
+    }
 }