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/08/04 13:02:01 UTC

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

Author: coheigea
Date: Tue Aug  4 11:02:01 2015
New Revision: 1694032

URL: http://svn.apache.org/r1694032
Log:
[WSS-549] - Don't write out a ReferenceList if there are no elements to encrypt


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

Modified:
    webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecDKEncrypt.java
    webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecEncrypt.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=1694032&r1=1694031&r2=1694032&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 Tue Aug  4 11:02:01 2015
@@ -183,13 +183,15 @@ public class WSSecDKEncrypt extends WSSe
      * @param secHeader The security header.
      */
     public void addExternalRefElement(Element referenceList, WSSecHeader secHeader) {
-        Node node = dkt.getElement().getNextSibling();
-        if (node != null && Node.ELEMENT_NODE == node.getNodeType()) {
-            secHeader.getSecurityHeader().insertBefore(referenceList, node);
-        } else {
-            // If (at this moment) DerivedKeyToken is the LAST element of 
-            // the security header 
-            secHeader.getSecurityHeader().appendChild(referenceList);
+        if (referenceList != null) {
+            Node node = dkt.getElement().getNextSibling();
+            if (node != null && Node.ELEMENT_NODE == node.getNodeType()) {
+                secHeader.getSecurityHeader().insertBefore(referenceList, node);
+            } else {
+                // If (at this moment) DerivedKeyToken is the LAST element of 
+                // the security header 
+                secHeader.getSecurityHeader().appendChild(referenceList);
+            }
         }
     }
 

Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecEncrypt.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/WSSecEncrypt.java?rev=1694032&r1=1694031&r2=1694032&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecEncrypt.java (original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecEncrypt.java Tue Aug  4 11:02:01 2015
@@ -285,6 +285,10 @@ public class WSSecEncrypt extends WSSecE
                 document, getWsConfig(), keyInfo, secretKeySpec, symEncAlgo, references, callbackLookup,
                     attachmentCallbackHandler, attachmentEncryptedDataElements, storeBytesInAttachment
             );
+        if (encDataRefs.isEmpty()) {
+            return null;
+        }
+        
         if (dataRef == null) {
             dataRef = 
                 document.createElementNS(
@@ -314,7 +318,9 @@ public class WSSecEncrypt extends WSSecE
      * @param dataRef The internal <code>enc:Reference</code> element
      */
     public void addInternalRefElement(Element dataRef) {
-        encryptedKeyElement.appendChild(dataRef);
+        if (dataRef != null) {
+            encryptedKeyElement.appendChild(dataRef);
+        }
     }
 
     /**
@@ -328,7 +334,9 @@ public class WSSecEncrypt extends WSSecE
      * @param secHeader The security header.
      */
     public void addExternalRefElement(Element dataRef, WSSecHeader secHeader) {
-        WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), dataRef);
+        if (dataRef != null) {
+            WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), dataRef);
+        }
     }
 
     public void addAttachmentEncryptedDataElements(WSSecHeader secHeader) {