cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Initial negative client cert token binding test
Date Tue, 25 Apr 2017 20:58:23 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 90a248537 -> 64035f8fa


Initial negative client cert token binding test


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

Branch: refs/heads/3.1.x-fixes
Commit: 64035f8fa8e6c48981a830e1eed7d678381763eb
Parents: 90a2485
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Apr 25 17:19:54 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Apr 25 21:58:03 2017 +0100

----------------------------------------------------------------------
 .../oauth2/filters/OAuthRequestFilter.java      |  5 ++-
 .../security/oauth2/tls/JAXRSOAuth2TlsTest.java | 20 ++++++++---
 .../jaxrs/security/oauth2/tls/client2.xml       | 38 ++++++++++++++++++++
 .../jaxrs/security/oauth2/tls/serverTls.xml     |  5 +++
 4 files changed, 61 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/64035f8f/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/OAuthRequestFilter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/OAuthRequestFilter.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/OAuthRequestFilter.java
index e432193..a9cb0fc 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/OAuthRequestFilter.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/OAuthRequestFilter.java
@@ -154,8 +154,7 @@ public class OAuthRequestFilter extends AbstractAccessTokenValidator
             String message = "The token has been authorized by the resource owner "
                 + "using an unsupported authentication method";
             LOG.warning(message);
-            throw ExceptionUtils.toForbiddenException(null, null);
-            
+            throw ExceptionUtils.toNotAuthorizedException(null, null);
         }
 
         // Check Client Certificate Binding if any
@@ -164,7 +163,7 @@ public class OAuthRequestFilter extends AbstractAccessTokenValidator
             TLSSessionInfo tlsInfo = getTlsSessionInfo();
             X509Certificate cert = tlsInfo == null ? null : OAuthUtils.getRootTLSCertificate(tlsInfo);
             if (cert == null || !OAuthUtils.compareCertificateThumbprints(cert, certThumbprint))
{ 
-                throw ExceptionUtils.toForbiddenException(null, null);
+                throw ExceptionUtils.toNotAuthorizedException(null, null);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/64035f8f/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/tls/JAXRSOAuth2TlsTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/tls/JAXRSOAuth2TlsTest.java
b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/tls/JAXRSOAuth2TlsTest.java
index 3824259..50bfea3 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/tls/JAXRSOAuth2TlsTest.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/tls/JAXRSOAuth2TlsTest.java
@@ -59,10 +59,22 @@ public class JAXRSOAuth2TlsTest extends AbstractBusClientServerTestBase
{
         ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new CustomGrant());
         assertNotNull(at.getTokenKey());
         
-        String rsAddress = "https://localhost:" + PORT + "/rs/bookstore/books/123";
-        WebClient wcRs = createRsWebClient(rsAddress, at);
+        String protectedRsAddress = "https://localhost:" + PORT + "/rs/bookstore/books/123";
+        WebClient wcRs = createRsWebClient(protectedRsAddress, at, "client.xml");
         Book book = wcRs.get(Book.class);
         assertEquals(123L, book.getId());
+        
+        
+        String unprotectedRsAddress = "https://localhost:" + PORT + "/rsUnprotected/bookstore/books/123";
+        WebClient wcRsDiffClientCert = createRsWebClient(unprotectedRsAddress, at, "client2.xml");
+        // Unprotected resource
+        book = wcRsDiffClientCert.get(Book.class);
+        assertEquals(123L, book.getId());
+        
+        // Protected resource, access token was created with Morphit key, RS is accessed
with
+        // Bethal.key, thus 401 is expected
+        wcRsDiffClientCert = createRsWebClient(protectedRsAddress, at, "client2.xml");
+        assertEquals(401, wcRsDiffClientCert.get().getStatus());
     }
     
     @Test
@@ -105,12 +117,12 @@ public class JAXRSOAuth2TlsTest extends AbstractBusClientServerTestBase
{
         wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON);
         return wc;
     }
-    private WebClient createRsWebClient(String address, ClientAccessToken at) {
+    private WebClient createRsWebClient(String address, ClientAccessToken at, String clientContext)
{
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
         bean.setAddress(address);
 
         SpringBusFactory bf = new SpringBusFactory();
-        URL busFile = JAXRSOAuth2TlsTest.class.getResource("client.xml");
+        URL busFile = JAXRSOAuth2TlsTest.class.getResource(clientContext);
         Bus springBus = bf.createBus(busFile.toString());
         bean.setBus(springBus);
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/64035f8f/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/client2.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/client2.xml
b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/client2.xml
new file mode 100644
index 0000000..826e876
--- /dev/null
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/client2.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core" xmlns:p="http://cxf.apache.org/policy" xmlns:sec="http://cxf.apache.org/configuration/security"
xsi:schemaLocation="           http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
          http://cxf.apache.org/jaxws                           http://cxf.apache.org/schemas/jaxws.xsd
          http://cxf.apache.org/transports/http/configuration   http://cxf.apache.org/schemas/configuration/http-conf.xsd
          http://cxf.apache.org/configuration/security          http://cxf.apache.org/schemas/configuration/security.xsd
          http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd           http://cxf.apache.org/policy
http://cxf.apache.org/schemas/
 policy.xsd">
+    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+    <cxf:bus>
+        <cxf:features>
+            <cxf:logging/>
+        </cxf:features>
+    </cxf:bus>
+    <http:conduit name="https://localhost.*">
+        <http:client ConnectionTimeout="3000000" ReceiveTimeout="3000000"/>
+        <http:tlsClientParameters disableCNCheck="true">
+            <sec:keyManagers keyPassword="password">
+                <sec:keyStore type="JKS" password="password" resource="keys/Bethal.jks"/>
+            </sec:keyManagers>
+            <sec:trustManagers>
+                <sec:keyStore type="JKS" password="password" resource="keys/Truststore.jks"/>
+            </sec:trustManagers>
+        </http:tlsClientParameters>
+    </http:conduit>
+</beans>

http://git-wip-us.apache.org/repos/asf/cxf/blob/64035f8f/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/serverTls.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/serverTls.xml
b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/serverTls.xml
index 219bf45..40ade66 100644
--- a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/serverTls.xml
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/tls/serverTls.xml
@@ -113,6 +113,11 @@ under the License.
             <ref bean="oauth2Filter1"/>
         </jaxrs:providers>
     </jaxrs:server>
+    <jaxrs:server id="rsServerUnprotected" address="https://localhost:${testutil.ports.jaxrs-oauth2-tls}/rsUnprotected">
+        <jaxrs:serviceBeans>
+            <ref bean="rsService"/>
+        </jaxrs:serviceBeans>
+    </jaxrs:server>
     
     
     <http:conduit name="https://localhost.*">


Mime
View raw message