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:51:57 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 98c61725f -> e7a890acf


Using CXF APIs instead to get a Document

# Conflicts:
#	rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/AuthnRequestBuilderTest.java
#	rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/CombinedValidatorTest.java
#	rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLResponseValidatorTest.java
#	rt/rs/security/sso/saml/src/test/java/org/apache/cxf/rs/security/saml/sso/SAMLSSOResponseValidatorTest.java


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

Branch: refs/heads/3.1.x-fixes
Commit: 8d58916afe4c154fcec2f73b7cccf69d0e06ec2b
Parents: 98c6172
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 19:51:49 2017 +0100

----------------------------------------------------------------------
 .../saml/sso/AuthnRequestBuilderTest.java       |  21 +---
 .../saml/sso/CombinedValidatorTest.java         |  32 ++---
 .../saml/sso/SAMLResponseValidatorTest.java     | 125 ++++++-------------
 .../saml/sso/SAMLSSOResponseValidatorTest.java  |  27 ++--
 4 files changed, 64 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/8d58916a/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 8b58799..b9033cd 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,12 +46,9 @@ 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();
-        
-        Issuer issuer = 
+        Document doc = DOMUtils.createDocument();
+
+        Issuer issuer =
             SamlpRequestComponentBuilder.createIssuer("http://localhost:9001/app");
         NameIDPolicy nameIDPolicy = 
             SamlpRequestComponentBuilder.createNameIDPolicy(
@@ -86,11 +80,8 @@ 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/8d58916a/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 cb684ed..3210d42 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;
@@ -60,21 +58,17 @@ import org.opensaml.xmlsec.signature.support.SignatureConstants;
  * Some unit tests for the SAMLProtocolResponseValidator and the SAMLSSOResponseValidator
  */
 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);
         
         Element responseElement = OpenSAMLUtil.toDom(response, 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);
@@ -186,10 +178,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();
@@ -232,10 +221,9 @@ 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);
         
         Element responseElement = OpenSAMLUtil.toDom(response, doc);

http://git-wip-us.apache.org/repos/asf/cxf/blob/8d58916a/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 f33a63b..caeb35a 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,12 +67,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -109,12 +103,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML1_STATUSCODE_SUCCESS, null
             );
@@ -153,12 +144,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 "urn:oasis:names:tc:SAML:2.0:status:RequestDenied", null
             );
@@ -197,12 +185,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -255,12 +240,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -318,12 +300,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -375,12 +354,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -432,12 +408,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -568,12 +541,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -614,12 +584,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -660,12 +627,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -705,12 +669,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -750,12 +711,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -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/8d58916a/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 ed4e5e2..6cd6789 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,12 +217,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -589,12 +584,9 @@ 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();
-        
-        Status status = 
+        Document doc = DOMUtils.createDocument();
+
+        Status status =
             SAML2PResponseComponentBuilder.createStatus(
                 SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null
             );
@@ -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