Repository: cxf Updated Branches: refs/heads/master aeba7ad5a -> dc47b8e0d
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/dc47b8e0 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/dc47b8e0 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/dc47b8e0 Branch: refs/heads/master Commit: dc47b8e0dd28eece00bf87dcb8ce2efdde9441aa Parents: aeba7ad Author: Sergey Beryozkin <[email protected]> Authored: Tue Apr 25 17:19:54 2017 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Tue Apr 25 17:19:54 2017 +0100 ---------------------------------------------------------------------- .../oauth2/filters/OAuthRequestFilter.java | 4 +-- .../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(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/dc47b8e0/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 ec1e8fa..c3808d4 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,7 +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 @@ -163,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/dc47b8e0/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/dc47b8e0/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/dc47b8e0/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.*">
