cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: Switch to use W3CDOMStreamWriter for SAML SSO Metadata
Date Thu, 02 Jul 2015 14:20:22 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 01fbddbf6 -> fdab617d8


Switch to use W3CDOMStreamWriter for SAML SSO Metadata


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fdab617d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fdab617d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fdab617d

Branch: refs/heads/master
Commit: fdab617d828b66975ad44fac7bea4702ab66979e
Parents: 01fbddb
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Jul 2 15:19:57 2015 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Jul 2 15:19:57 2015 +0100

----------------------------------------------------------------------
 .../rs/security/saml/sso/MetadataWriter.java    | 27 +++++++-------------
 1 file changed, 9 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/fdab617d/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
index c094b95..8363199 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/MetadataWriter.java
@@ -19,9 +19,6 @@
 
 package org.apache.cxf.rs.security.saml.sso;
 
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
 import java.net.MalformedURLException;
 import java.security.Key;
 import java.security.cert.CertificateEncodingException;
@@ -49,8 +46,8 @@ import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Document;
 
-import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
-import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
+import org.apache.wss4j.common.util.DOM2Writer;
 import org.apache.xml.security.stax.impl.util.IDGenerator;
 import org.apache.xml.security.utils.Base64;
 import org.slf4j.Logger;
@@ -72,9 +69,7 @@ public class MetadataWriter {
         boolean wantRequestsSigned
     ) throws Exception {
 
-        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(4096);
-        Writer streamWriter = new OutputStreamWriter(bout, "UTF-8");
-        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(streamWriter);
+        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
 
         writer.writeStartDocument("UTF-8", "1.0");
 
@@ -94,22 +89,21 @@ public class MetadataWriter {
 
         writer.writeEndDocument();
 
-        streamWriter.flush();
-        bout.flush();
+        writer.close();
 
         if (LOG.isDebugEnabled()) {
-            String out = new String(bout.toByteArray());
+            String out = DOM2Writer.nodeToString(writer.getDocument());
             LOG.debug("***************** unsigned ****************");
             LOG.debug(out);
             LOG.debug("***************** unsigned ****************");
         }
 
-        InputStream is = bout.createInputStream();
+        Document doc = writer.getDocument();
 
         if (signingKey != null) {
-            return signMetaInfo(signingCert, signingKey, is, referenceID);
+            return signMetaInfo(signingCert, signingKey, doc, referenceID);
         }
-        return StaxUtils.read(is);
+        return doc;
     }
     
     private void writeSAMLMetadata(
@@ -194,7 +188,7 @@ public class MetadataWriter {
     }
 
     private static Document signMetaInfo(X509Certificate signingCert, Key signingKey, 
-                                         InputStream metaInfo, String referenceID
+                                         Document doc, String referenceID
     ) throws Exception {
         String signatureMethod = null;
         if ("SHA1withDSA".equals(signingCert.getSigAlgName())) {
@@ -239,9 +233,6 @@ public class MetadataWriter {
         X509Data xd = kif.newX509Data(x509Content);
         KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));
 
-        // Instantiate the document to be signed.
-        Document doc = StaxUtils.read(metaInfo);
-
         // Create a DOMSignContext and specify the RSA PrivateKey and
         // location of the resulting XMLSignature's parent element.
         //DOMSignContext dsc = new DOMSignContext(keyEntry.getPrivateKey(), doc.getDocumentElement());


Mime
View raw message