Author: coheigea
Date: Tue Nov 12 12:19:07 2013
New Revision: 1541032

URL: http://svn.apache.org/r1541032
Log:
[WSS-430] - Added support for c14n when using a MIME ContentType with a CharSet

Modified:
    
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/transform/AttachmentContentSignatureTransform.java
    
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/transformer/AttachmentContentSignatureTransform.java

Modified: 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/transform/AttachmentContentSignatureTransform.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/transform/AttachmentContentSignatureTransform.java?rev=1541032&r1=1541031&r2=1541032&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/transform/AttachmentContentSignatureTransform.java
 (original)
+++ 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/transform/AttachmentContentSignatureTransform.java
 Tue Nov 12 12:19:07 2013
@@ -170,26 +170,32 @@ public class AttachmentContentSignatureT
             }
 
             String mimeType = attachment.getMimeType();
-            if ("text/xml".equalsIgnoreCase(mimeType) ||
-                    "application/xml".equals(mimeType) ||
-                    mimeType != null && mimeType.endsWith("+xml")) {    //e.g. 
Application/mathml+xml
-                   /* 5.4.2:
-                    * Content of an XML Content-Type MUST be XML canonicalized 
using
-                    * Exclusive XML Canonicalization without comments,as 
specified by
-                    * the URI http://www.w3.org/2001/10/xml-exc-c14n# 
[Excl-Canon].
-                    * The reason for requiring Exclusive Canonicalization is 
that many
-                    * implementations will support Exclusive Canonicalization 
for other
-                    * XML Signature purposes, since this form of 
canonicalization
-                    * supports context changes. The InclusiveNamespace 
PrefixList
-                    * attribute SHOULD be empty or not present.
-                    */
+            String lowerCaseMimeType = null;
+            if (mimeType != null) {
+                lowerCaseMimeType = mimeType.toLowerCase();
+            }
+            
+            if (lowerCaseMimeType != null 
+                && (lowerCaseMimeType.startsWith("text/xml")
+                    || lowerCaseMimeType.startsWith("application/xml")
+                    || lowerCaseMimeType.matches("application/.*xml.*"))) {
+                /* 5.4.2:
+                 * Content of an XML Content-Type MUST be XML canonicalized 
using
+                 * Exclusive XML Canonicalization without comments,as 
specified by
+                 * the URI http://www.w3.org/2001/10/xml-exc-c14n# 
[Excl-Canon].
+                 * The reason for requiring Exclusive Canonicalization is that 
many
+                 * implementations will support Exclusive Canonicalization for 
other
+                 * XML Signature purposes, since this form of canonicalization
+                 * supports context changes. The InclusiveNamespace PrefixList
+                 * attribute SHOULD be empty or not present.
+                 */
                 Canonicalizer canon = 
Canonicalizer.getInstance(WSConstants.C14N_EXCL_OMIT_COMMENTS);
                 canon.setWriter(outputStream);
 
                 XMLSignatureInput xmlSignatureInput = new 
XMLSignatureInput(inputStream);
                 canon.canonicalizeXPathNodeSet(xmlSignatureInput.getNodeSet());
 
-            } else if (mimeType != null && mimeType.startsWith("text/")) {
+            } else if (lowerCaseMimeType != null && 
lowerCaseMimeType.startsWith("text/")) {
                 CRLFOutputStream crlfOutputStream = new 
CRLFOutputStream(outputStream);
                 int numBytes;
                 byte[] buf = new byte[8192];

Modified: 
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/transformer/AttachmentContentSignatureTransform.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/transformer/AttachmentContentSignatureTransform.java?rev=1541032&r1=1541031&r2=1541032&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/transformer/AttachmentContentSignatureTransform.java
 (original)
+++ 
webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/transformer/AttachmentContentSignatureTransform.java
 Tue Nov 12 12:19:07 2013
@@ -27,6 +27,7 @@ import org.apache.xml.security.stax.impl
 import 
org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclOmitCommentsTransformer;
 
 import javax.xml.stream.XMLStreamException;
+
 import java.io.InputStream;
 import java.util.Map;
 
@@ -73,19 +74,25 @@ public class AttachmentContentSignatureT
     @Override
     public void transform(InputStream inputStream) throws XMLStreamException {
         String mimeType = getAttachment().getMimeType();
-        if ("text/xml".equalsIgnoreCase(mimeType) ||
-                "application/xml".equals(mimeType) ||
-                mimeType != null && mimeType.endsWith("+xml")) {    //e.g. 
Application/mathml+xml
-                   /* 5.4.2:
-                    * Content of an XML Content-Type MUST be XML canonicalized 
using
-                    * Exclusive XML Canonicalization without comments,as 
specified by
-                    * the URI http://www.w3.org/2001/10/xml-exc-c14n# 
[Excl-Canon].
-                    * The reason for requiring Exclusive Canonicalization is 
that many
-                    * implementations will support Exclusive Canonicalization 
for other
-                    * XML Signature purposes, since this form of 
canonicalization
-                    * supports context changes. The InclusiveNamespace 
PrefixList
-                    * attribute SHOULD be empty or not present.
-                    */
+        String lowerCaseMimeType = null;
+        if (mimeType != null) {
+            lowerCaseMimeType = mimeType.toLowerCase();
+        }
+        
+        if (lowerCaseMimeType != null 
+            && (lowerCaseMimeType.startsWith("text/xml")
+                || lowerCaseMimeType.startsWith("application/xml")
+                || lowerCaseMimeType.matches("application/.*xml.*"))) {
+            /* 5.4.2:
+             * Content of an XML Content-Type MUST be XML canonicalized using
+             * Exclusive XML Canonicalization without comments,as specified by
+             * the URI http://www.w3.org/2001/10/xml-exc-c14n# [Excl-Canon].
+             * The reason for requiring Exclusive Canonicalization is that many
+             * implementations will support Exclusive Canonicalization for 
other
+             * XML Signature purposes, since this form of canonicalization
+             * supports context changes. The InclusiveNamespace PrefixList
+             * attribute SHOULD be empty or not present.
+             */
             Canonicalizer20010315_ExclOmitCommentsTransformer canon =
                     new Canonicalizer20010315_ExclOmitCommentsTransformer();
             try {
@@ -95,7 +102,7 @@ public class AttachmentContentSignatureT
             }
             canon.transform(inputStream);
 
-        } else if (mimeType != null && mimeType.startsWith("text/")) {
+        } else if (lowerCaseMimeType != null && 
lowerCaseMimeType.startsWith("text/")) {
             CRLFOutputStream crlfOutputStream = new 
CRLFOutputStream(getOutputStream());
             try {
                 setOutputStream(crlfOutputStream);


Reply via email to