You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/03/22 16:20:56 UTC

[cxf] branch 3.1.x-fixes updated (5e3855a -> aa1bd8b)

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a change to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git.


    from 5e3855a  Recording .gitmergeinfo Changes
     new 6b5903a  CXF-7687 - AuthorizationPolicy: AuthorizationType="Bearer" has no effect
     new 79c743f  Recording .gitmergeinfo Changes
     new aa1bd8b  Fixing merge

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitmergeinfo                                      |  1 +
 .../org/apache/cxf/transport/http/HTTPConduit.java | 15 +++--
 ...goAuthSupplier.java => CustomAuthSupplier.java} | 19 +++---
 .../systest/jaxrs/security/saml/JAXRSSamlTest.java | 68 ++++++++++++++++++++++
 .../jaxrs/security/saml/SamlCallbackHandler.java   | 21 +++++--
 5 files changed, 106 insertions(+), 18 deletions(-)
 copy rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/{SpnegoAuthSupplier.java => CustomAuthSupplier.java} (67%)

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

[cxf] 01/03: CXF-7687 - AuthorizationPolicy: AuthorizationType="Bearer" has no effect

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 6b5903a97f2945342569e3d4595a7dd514b3242a
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Mar 22 14:59:55 2018 +0000

    CXF-7687 - AuthorizationPolicy: AuthorizationType="Bearer" has no effect
    
    (cherry picked from commit 203c8a2731bdd44ce102e983d8b97f63cfa283f5)
    
    # Conflicts:
    #	rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    #	systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java
    #	systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/SamlCallbackHandler.java
---
 .../org/apache/cxf/transport/http/HTTPConduit.java | 15 +++--
 .../transport/http/auth/CustomAuthSupplier.java    | 45 ++++++++++++++
 .../systest/jaxrs/security/saml/JAXRSSamlTest.java | 69 ++++++++++++++++++++++
 .../jaxrs/security/saml/SamlCallbackHandler.java   | 21 +++++--
 4 files changed, 139 insertions(+), 11 deletions(-)

diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
index 4fbaa7c..a3042e0 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
@@ -75,6 +75,7 @@ import org.apache.cxf.transport.AbstractConduit;
 import org.apache.cxf.transport.Assertor;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.auth.CustomAuthSupplier;
 import org.apache.cxf.transport.http.auth.DefaultBasicAuthSupplier;
 import org.apache.cxf.transport.http.auth.DigestAuthSupplier;
 import org.apache.cxf.transport.http.auth.HttpAuthHeader;
@@ -157,10 +158,10 @@ public abstract class HTTPConduit
      */
     public static final String KEY_HTTP_CONNECTION = "http.connection";
     public static final String KEY_HTTP_CONNECTION_ADDRESS = "http.connection.address";
-    
+
     public static final String SET_HTTP_RESPONSE_MESSAGE = "org.apache.cxf.transport.http.set.response.message";
     public static final String HTTP_RESPONSE_MESSAGE = "http.responseMessage";
-    
+
     public static final String PROCESS_FAULT_ON_HTTP_400 = "org.apache.cxf.transport.process_fault_on_http_400";
     public static final String NO_IO_EXCEPTIONS = "org.apache.cxf.transport.no_io_exceptions";
     /**
@@ -515,11 +516,11 @@ public abstract class HTTPConduit
         int chunkThreshold = 0;
         final AuthorizationPolicy effectiveAuthPolicy = getEffectiveAuthPolicy(message);
         if (this.authSupplier == null) {
-            this.authSupplier = createAuthSupplier(effectiveAuthPolicy.getAuthorizationType());
+            this.authSupplier = createAuthSupplier(effectiveAuthPolicy);
         }
         
         if (this.proxyAuthSupplier == null) {
-            this.proxyAuthSupplier = createAuthSupplier(proxyAuthorizationPolicy.getAuthorizationType());
+            this.proxyAuthSupplier = createAuthSupplier(proxyAuthorizationPolicy);
         }
 
         if (this.authSupplier.requiresRequestCaching()) {
@@ -591,11 +592,15 @@ public abstract class HTTPConduit
                                                        boolean isChunking,
                                                        int chunkThreshold) throws IOException;
     
-    private HttpAuthSupplier createAuthSupplier(String authType) {
+    private HttpAuthSupplier createAuthSupplier(AuthorizationPolicy authzPolicy) {
+        String authType = authzPolicy.getAuthorizationType();
         if (HttpAuthHeader.AUTH_TYPE_NEGOTIATE.equals(authType)) {
             return new SpnegoAuthSupplier();
         } else if (HttpAuthHeader.AUTH_TYPE_DIGEST.equals(authType)) {
             return new DigestAuthSupplier();
+        } else if (authType != null && !HttpAuthHeader.AUTH_TYPE_BASIC.equals(authType)
+            && authzPolicy.getAuthorization() != null) {
+            return new CustomAuthSupplier();
         } else {
             return new DefaultBasicAuthSupplier();
         }
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/CustomAuthSupplier.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/CustomAuthSupplier.java
new file mode 100644
index 0000000..1066234
--- /dev/null
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/CustomAuthSupplier.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.http.auth;
+
+import java.net.URI;
+
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.message.Message;
+
+/**
+ * Use the AuthorizationPolicy type + value to create the authorization header.
+ */
+public final class CustomAuthSupplier implements HttpAuthSupplier {
+
+    public boolean requiresRequestCaching() {
+        return false;
+    }
+
+    public String getAuthorization(AuthorizationPolicy  authPolicy,
+                                   URI currentURI,
+                                   Message message,
+                                   String fullHeader) {
+        if (authPolicy.getAuthorizationType() != null && authPolicy.getAuthorization() != null) {
+            return authPolicy.getAuthorizationType() + " " + authPolicy.getAuthorization();
+        }
+        return null;
+    }
+
+}
\ No newline at end of file
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java
index 22509ce..4c4e877 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java
@@ -19,7 +19,9 @@
 
 package org.apache.cxf.systest.jaxrs.security.saml;
 
+import java.io.StringWriter;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -30,14 +32,22 @@ import javax.ws.rs.core.Form;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.common.util.Base64Exception;
+import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.provider.FormEncodingProvider;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.rs.security.saml.DeflateEncoderDecoder;
 import org.apache.cxf.rs.security.saml.SamlEnvelopedOutInterceptor;
 import org.apache.cxf.rs.security.saml.SamlFormOutInterceptor;
 import org.apache.cxf.rs.security.saml.SamlHeaderOutInterceptor;
@@ -45,7 +55,14 @@ import org.apache.cxf.rs.security.xml.XmlSigOutInterceptor;
 import org.apache.cxf.rt.security.SecurityConstants;
 import org.apache.cxf.systest.jaxrs.security.Book;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.wss4j.common.WSS4JConstants;
+import org.apache.wss4j.common.saml.SAMLCallback;
+import org.apache.wss4j.common.saml.SAMLUtil;
+import org.apache.wss4j.common.saml.SamlAssertionWrapper;
 import org.apache.wss4j.common.saml.builder.SAML2Constants;
+import org.apache.wss4j.common.util.DOM2Writer;
 import org.apache.wss4j.dom.WSConstants;
 
 import org.junit.BeforeClass;
@@ -61,6 +78,49 @@ public class JAXRSSamlTest extends AbstractBusClientServerTestBase {
     }
     
     @Test
+    public void testSAMLTokenHeaderUsingAuthorizationPolicy() throws Exception {
+        String address = "https://localhost:" + PORT + "/samlheader/bookstore/books/123";
+
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress(address);
+
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = JAXRSSamlTest.class.getResource("client.xml");
+        Bus springBus = bf.createBus(busFile.toString());
+        bean.setBus(springBus);
+
+        // Create SAML Token
+        SAMLCallback samlCallback = new SAMLCallback();
+        SAMLUtil.doSAMLCallback(new SamlCallbackHandler(), samlCallback);
+        SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
+        Document doc = DOMUtils.createDocument();
+        Element token = assertion.toDOM(doc);
+
+        WebClient wc =  bean.createWebClient();
+
+        HTTPConduit http = (HTTPConduit) WebClient.getConfig(wc).getConduit();
+        AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
+        String encodedToken = encodeToken(DOM2Writer.nodeToString(token));
+        authorizationPolicy.setAuthorization(encodedToken);
+        authorizationPolicy.setAuthorizationType("SAML");
+        http.setAuthorization(authorizationPolicy);
+
+        try {
+            Book book = wc.get(Book.class);
+            assertEquals(123L, book.getId());
+        } catch (WebApplicationException ex) {
+            fail(ex.getMessage());
+        } catch (ProcessingException ex) {
+            if (ex.getCause() != null && ex.getCause().getMessage() != null) {
+                fail(ex.getCause().getMessage());
+            } else {
+                fail(ex.getMessage());
+            }
+        }
+
+    }
+
+    @Test
     public void testGetBookSAMLTokenAsHeader() throws Exception {
         String address = "https://localhost:" + PORT + "/samlheader/bookstore/books/123";
         
@@ -271,4 +331,13 @@ public class JAXRSSamlTest extends AbstractBusClientServerTestBase {
         }
         return bean.createWebClient();
     }
+
+    private String encodeToken(String assertion) throws Base64Exception {
+        byte[] tokenBytes = assertion.getBytes(StandardCharsets.UTF_8);
+
+        tokenBytes = new DeflateEncoderDecoder().deflateToken(tokenBytes);
+        StringWriter writer = new StringWriter();
+        Base64Utility.encode(tokenBytes, 0, tokenBytes.length, writer);
+        return writer.toString();
+    }
 }
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/SamlCallbackHandler.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/SamlCallbackHandler.java
index 5a6b26f..42666fa 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/SamlCallbackHandler.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/SamlCallbackHandler.java
@@ -87,8 +87,11 @@ public class SamlCallbackHandler implements CallbackHandler {
                     callback.setSamlVersion(Version.SAML_11);
                 }
                 callback.setIssuer("https://idp.example.org/SAML2");
-                
-                String subjectName = (String)m.getContextualProperty("saml.subject.name");
+
+                String subjectName = null;
+                if (m != null) {
+                    subjectName = (String)m.getContextualProperty("saml.subject.name");
+                }
                 if (subjectName == null) {
                     subjectName = "uid=sts-client,o=mock-sts.com";
                 }
@@ -148,8 +151,11 @@ public class SamlCallbackHandler implements CallbackHandler {
                 
                 AttributeStatementBean attrBean = new AttributeStatementBean();
                 attrBean.setSubject(subjectBean);
-                
-                List<String> roles = CastUtils.cast((List<?>)m.getContextualProperty("saml.roles"));
+
+                List<String> roles = null;
+                if (m != null) {
+                    roles = CastUtils.cast((List<?>)m.getContextualProperty("saml.roles"));
+                }
                 if (roles == null) {
                     roles = Collections.singletonList("user");
                 }
@@ -160,8 +166,11 @@ public class SamlCallbackHandler implements CallbackHandler {
                 roleClaim.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_UNSPECIFIED);
                 roleClaim.setAttributeValues(new ArrayList<Object>(roles));
                 claims.add(roleClaim);
-                
-                List<String> authMethods = CastUtils.cast((List<?>)m.getContextualProperty("saml.auth"));
+
+                List<String> authMethods = null;
+                if (m != null) {
+                    authMethods = CastUtils.cast((List<?>)m.getContextualProperty("saml.auth"));
+                }
                 if (authMethods == null) {
                     authMethods = Collections.singletonList("password");
                 }

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

[cxf] 03/03: Fixing merge

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit aa1bd8bb2c8a64b763bf8c63e8b53d408f6bcdbb
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Mar 22 15:10:55 2018 +0000

    Fixing merge
---
 .../java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java   | 1 -
 1 file changed, 1 deletion(-)

diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java
index 4c4e877..160998c 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/saml/JAXRSSamlTest.java
@@ -57,7 +57,6 @@ import org.apache.cxf.systest.jaxrs.security.Book;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.apache.cxf.transport.http.HTTPConduit;
-import org.apache.wss4j.common.WSS4JConstants;
 import org.apache.wss4j.common.saml.SAMLCallback;
 import org.apache.wss4j.common.saml.SAMLUtil;
 import org.apache.wss4j.common.saml.SamlAssertionWrapper;

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

[cxf] 02/03: Recording .gitmergeinfo Changes

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 79c743f65865815be03041761f68f2782934d083
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Mar 22 15:02:28 2018 +0000

    Recording .gitmergeinfo Changes
---
 .gitmergeinfo | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 3b59853..c26080e 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -854,6 +854,7 @@ M 1cee603ce2c11509a6020ff77e96adae5cb256f0
 M 1d66475b4dea2a0031dcb1765e8e9fd08430ec9b
 M 1e57d379863d01b9330fff797c14d81a56b0b0f2
 M 1f9cbe3678c1984fd2fd57e26fdd5626841c32e9
+M 203c8a2731bdd44ce102e983d8b97f63cfa283f5
 M 20d0a2811c15cb65a402eb063e1359236d7014ea
 M 21031e3ab2ae227540e2a078d0336d894361acba
 M 21618dad08506cc80edde02cf1661cecd06c49ab

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.