Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1738118176 for ; Thu, 2 Jul 2015 14:20:23 +0000 (UTC) Received: (qmail 35299 invoked by uid 500); 2 Jul 2015 14:20:22 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 35234 invoked by uid 500); 2 Jul 2015 14:20:22 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 35225 invoked by uid 99); 2 Jul 2015 14:20:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jul 2015 14:20:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C3534E364C; Thu, 2 Jul 2015 14:20:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Message-Id: <0853111f11ab4065bd08bfce022494af@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: Switch to use W3CDOMStreamWriter for SAML SSO Metadata Date: Thu, 2 Jul 2015 14:20:22 +0000 (UTC) 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 Authored: Thu Jul 2 15:19:57 2015 +0100 Committer: Colm O hEigeartaigh 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());