cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [1/2] cxf git commit: Using CXF APIs instead to get a Document
Date Wed, 02 Aug 2017 18:49:35 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 598a45d5b -> 25cc43451


Using CXF APIs instead to get a Document


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

Branch: refs/heads/master
Commit: 2c5ee9592fd131c05945740010b7500f85f880cb
Parents: 598a45d
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Aug 2 15:21:48 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Aug 2 16:55:26 2017 +0100

----------------------------------------------------------------------
 .../saml/sso/AuthnRequestBuilderTest.java       | 15 +---
 .../saml/sso/CombinedValidatorTest.java         | 21 ++----
 .../saml/sso/SAMLResponseValidatorTest.java     | 73 ++++----------------
 .../saml/sso/SAMLSSOResponseValidatorTest.java  | 19 ++---
 4 files changed, 26 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/2c5ee959/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/AuthnRequestBuilderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/AuthnRequestBuilderTest.java
b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/AuthnRequestBuilderTest.java
index 4fbaa51..ff5caa8 100644
--- a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/AuthnRequestBuilderTest.java
+++ b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/AuthnRequestBuilderTest.java
@@ -21,12 +21,9 @@ package org.apache.cxf.rs.security.saml.sso;
 
 import java.util.Collections;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.wss4j.common.saml.OpenSAMLUtil;
@@ -49,10 +46,7 @@ public class AuthnRequestBuilderTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testCreateAuthnRequest() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Issuer issuer =
             SamlpRequestComponentBuilder.createIssuer("http://localhost:9001/app");
@@ -86,10 +80,7 @@ public class AuthnRequestBuilderTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testAuthnRequestBuilder() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         AuthnRequestBuilder authnRequestBuilder = new DefaultAuthnRequestBuilder();
         Message message = new MessageImpl();

http://git-wip-us.apache.org/repos/asf/cxf/blob/2c5ee959/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/CombinedValidatorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/CombinedValidatorTest.java
b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/CombinedValidatorTest.java
index d1c387f..c8046b0 100644
--- a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/CombinedValidatorTest.java
+++ b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/CombinedValidatorTest.java
@@ -25,11 +25,9 @@ import java.security.PrivateKey;
 import java.security.cert.X509Certificate;
 import java.util.Collections;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.crypto.CryptoType;
 import org.apache.wss4j.common.crypto.Merlin;
@@ -61,19 +59,15 @@ import org.opensaml.xmlsec.signature.support.SignatureConstants;
  */
 public class CombinedValidatorTest extends org.junit.Assert {
 
-    private static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
-
     static {
         WSSConfig.init();
         OpenSAMLUtil.initSamlEngine();
-        DOC_BUILDER_FACTORY.setNamespaceAware(true);
     }
 
     @org.junit.Test
     public void testSuccessfulValidation() throws Exception {
 
-        DocumentBuilder docBuilder = DOC_BUILDER_FACTORY.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Response response = createResponse(doc);
 
@@ -115,9 +109,7 @@ public class CombinedValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testWrappingAttack3() throws Exception {
-        DocumentBuilder docBuilder = DOC_BUILDER_FACTORY.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
-
+        Document doc = DOMUtils.createDocument();
         Response response = createResponse(doc);
 
         Element responseElement = OpenSAMLUtil.toDom(response, doc);
@@ -187,9 +179,7 @@ public class CombinedValidatorTest extends org.junit.Assert {
     @org.junit.Test
     public void testSuccessfulSignedValidation() throws Exception {
 
-        DocumentBuilder docBuilder = DOC_BUILDER_FACTORY.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
-
+        Document doc = DOMUtils.createDocument();
         Response response = createResponse(doc);
 
         Crypto issuerCrypto = new Merlin();
@@ -233,8 +223,7 @@ public class CombinedValidatorTest extends org.junit.Assert {
     @org.junit.Test
     public void testEnforceResponseSigned() throws Exception {
 
-        DocumentBuilder docBuilder = DOC_BUILDER_FACTORY.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Response response = createResponse(doc);
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/2c5ee959/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLResponseValidatorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLResponseValidatorTest.java
b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLResponseValidatorTest.java
index e92bb29..85f42c1 100644
--- a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLResponseValidatorTest.java
+++ b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLResponseValidatorTest.java
@@ -26,9 +26,6 @@ import java.security.cert.X509Certificate;
 import java.util.Collections;
 import java.util.List;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.apache.cxf.helpers.DOMUtils;
@@ -70,10 +67,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testCreateAndValidateResponse() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -109,10 +103,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testInvalidStatusCode() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -153,10 +144,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testRequestDeniedStatusCode() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -197,10 +185,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testResponseSignedAssertion() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -255,10 +240,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testResponseModifiedSignedAssertion() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -318,10 +300,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testSignedResponse() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -375,10 +354,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testModifiedSignedResponse() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -432,10 +408,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testSignedResponseNoKeyInfo() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -568,10 +541,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testResponseIssueInstant() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -614,10 +584,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testAssertionIssueInstant() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -660,10 +627,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testFutureAuthnInstant() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -705,10 +669,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testStaleSessionNotOnOrAfter() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -750,10 +711,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testInvalidSubjectLocality() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -859,10 +817,7 @@ public class SAMLResponseValidatorTest extends org.junit.Assert {
         SubjectConfirmationDataBean subjectConfirmationData,
         SAML2CallbackHandler callbackHandler
     ) throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(

http://git-wip-us.apache.org/repos/asf/cxf/blob/2c5ee959/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLSSOResponseValidatorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLSSOResponseValidatorTest.java
b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLSSOResponseValidatorTest.java
index e672761..f9beed9 100644
--- a/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLSSOResponseValidatorTest.java
+++ b/rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLSSOResponseValidatorTest.java
@@ -27,11 +27,9 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.crypto.CryptoType;
 import org.apache.wss4j.common.crypto.Merlin;
@@ -219,10 +217,7 @@ public class SAMLSSOResponseValidatorTest extends org.junit.Assert {
 
     @org.junit.Test
     public void testSignedResponseInvalidDestination() throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -589,10 +584,7 @@ public class SAMLSSOResponseValidatorTest extends org.junit.Assert {
         List<AudienceRestrictionBean> audienceRestrictions,
         String authnClassRef
     ) throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(
@@ -648,10 +640,7 @@ public class SAMLSSOResponseValidatorTest extends org.junit.Assert {
         SubjectConfirmationDataBean subjectConfirmationData,
         SAML2CallbackHandler callbackHandler
     ) throws Exception {
-        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-        docBuilderFactory.setNamespaceAware(true);
-        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-        Document doc = docBuilder.newDocument();
+        Document doc = DOMUtils.createDocument();
 
         Status status =
             SAML2PResponseComponentBuilder.createStatus(


Mime
View raw message