Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EE6B218930 for ; Thu, 3 Dec 2015 15:04:40 +0000 (UTC) Received: (qmail 34990 invoked by uid 500); 3 Dec 2015 15:04:37 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 34916 invoked by uid 500); 3 Dec 2015 15:04:37 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 34896 invoked by uid 99); 3 Dec 2015 15:04:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2015 15:04:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5CADAE680A; Thu, 3 Dec 2015 15:04:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Thu, 03 Dec 2015 15:04:37 -0000 Message-Id: <9ccbe1274611440994263ecbd8227f7e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] cxf git commit: Adding JWT tests Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 1f72ff889 -> 127fbc3c5 Adding JWT tests Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e9e7ff13 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e9e7ff13 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e9e7ff13 Branch: refs/heads/3.0.x-fixes Commit: e9e7ff13a428191249fcb8f45499978d968029cd Parents: 1f72ff8 Author: Colm O hEigeartaigh Authored: Thu Dec 3 14:47:00 2015 +0000 Committer: Colm O hEigeartaigh Committed: Thu Dec 3 15:04:12 2015 +0000 ---------------------------------------------------------------------- .../jose/jwt/BookServerJwtProperties.java | 59 +++ .../security/jose/jwt/JWTAlgorithmTest.java | 53 ++- .../security/jose/jwt/JWTAuthnAuthzTest.java | 7 +- .../security/jose/jwt/JWTPropertiesTest.java | 418 +++++++++++++++++++ .../security/jose/jwt/properties-server.xml | 72 ++++ 5 files changed, 601 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/e9e7ff13/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/BookServerJwtProperties.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/BookServerJwtProperties.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/BookServerJwtProperties.java new file mode 100644 index 0000000..b0db7ae --- /dev/null +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/BookServerJwtProperties.java @@ -0,0 +1,59 @@ +/** + * 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.systest.jaxrs.security.jose.jwt; + +import java.net.URL; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; +import org.apache.cxf.testutil.common.TestUtil; + +public class BookServerJwtProperties extends AbstractBusTestServerBase { + public static final String PORT = TestUtil.getPortNumber("jaxrs-jwt-properties"); + private static final URL SERVER_CONFIG_FILE = + BookServerJwtProperties.class.getResource("properties-server.xml"); + + protected void run() { + SpringBusFactory bf = new SpringBusFactory(); + Bus springBus = bf.createBus(SERVER_CONFIG_FILE); + BusFactory.setDefaultBus(springBus); + setBus(springBus); + + try { + new BookServerJwtProperties(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) { + try { + BookServerJwtProperties s = new BookServerJwtProperties(); + s.start(); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(-1); + } finally { + System.out.println("done!"); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e9e7ff13/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAlgorithmTest.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAlgorithmTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAlgorithmTest.java index 8487b1d..0ea623a 100644 --- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAlgorithmTest.java +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAlgorithmTest.java @@ -122,10 +122,6 @@ public class JWTAlgorithmTest extends AbstractBusClientServerTestBase { assertEquals(returnedBook.getId(), 123L); } - private List toList(String address) { - return Collections.singletonList(address); - } - @org.junit.Test public void testEncryptionDynamic() throws Exception { @@ -648,4 +644,53 @@ public class JWTAlgorithmTest extends AbstractBusClientServerTestBase { assertEquals(returnedBook.getName(), "book"); assertEquals(returnedBook.getId(), 123L); } + + // Include the cert in the "x5c" header + @org.junit.Test + public void testSignatureCertificateTest() throws Exception { + + URL busFile = JWTAlgorithmTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/signedjwtincludecert/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setIssuedAt(new Date().getTime() / 1000L); + claims.setAudiences(toList(address)); + + JwtToken token = new JwtToken(claims); + + Map properties = new HashMap(); + properties.put("rs.security.keystore.type", "jks"); + properties.put("rs.security.keystore.password", "password"); + properties.put("rs.security.key.password", "password"); + properties.put("rs.security.keystore.alias", "alice"); + properties.put("rs.security.keystore.file", + "org/apache/cxf/systest/jaxrs/security/certs/alice.jks"); + properties.put("rs.security.signature.algorithm", "RS256"); + properties.put("rs.security.signature.include.cert", "true"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertEquals(response.getStatus(), 200); + + Book returnedBook = response.readEntity(Book.class); + assertEquals(returnedBook.getName(), "book"); + assertEquals(returnedBook.getId(), 123L); + } + + private List toList(String address) { + return Collections.singletonList(address); + } + } http://git-wip-us.apache.org/repos/asf/cxf/blob/e9e7ff13/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAuthnAuthzTest.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAuthnAuthzTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAuthnAuthzTest.java index 0e012e7..6ee8ff0 100644 --- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAuthnAuthzTest.java +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTAuthnAuthzTest.java @@ -107,10 +107,6 @@ public class JWTAuthnAuthzTest extends AbstractBusClientServerTestBase { assertEquals(returnedBook.getId(), 123L); } - private List toList(String address) { - return Collections.singletonList(address); - } - @org.junit.Test public void testAuthenticationFailure() throws Exception { @@ -264,4 +260,7 @@ public class JWTAuthnAuthzTest extends AbstractBusClientServerTestBase { assertNotEquals(response.getStatus(), 200); } + private List toList(String address) { + return Collections.singletonList(address); + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/e9e7ff13/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java new file mode 100644 index 0000000..7ce86d3 --- /dev/null +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java @@ -0,0 +1,418 @@ +/** + * 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.systest.jaxrs.security.jose.jwt; + +import java.net.URL; +import java.security.Security; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.Response; + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter; +import org.apache.cxf.rs.security.jose.jwt.JwtClaims; +import org.apache.cxf.rs.security.jose.jwt.JwtConstants; +import org.apache.cxf.rs.security.jose.jwt.JwtToken; +import org.apache.cxf.systest.jaxrs.security.Book; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +/** + * Some tests for various properties of JWT tokens. + */ +public class JWTPropertiesTest extends AbstractBusClientServerTestBase { + public static final String PORT = BookServerJwtProperties.PORT; + + @BeforeClass + public static void startServers() throws Exception { + assertTrue("server did not launch correctly", + launchServer(BookServerJwtProperties.class, true)); + registerBouncyCastleIfNeeded(); + } + + private static void registerBouncyCastleIfNeeded() throws Exception { + // Still need it for Oracle Java 7 and Java 8 + Security.addProvider(new BouncyCastleProvider()); + } + + @AfterClass + public static void unregisterBouncyCastleIfNeeded() throws Exception { + Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); + } + + @org.junit.Test + public void testExpiredToken() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setIssuedAt(new Date().getTime() / 1000L); + claims.setAudiences(toList(address)); + + // Set the expiry date to be yesterday + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DATE, -1); + claims.setExpiryTime(cal.getTimeInMillis() / 1000L); + + JwtToken token = new JwtToken(claims); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertNotEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testFutureToken() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setAudiences(toList(address)); + + // Set the issued date to be in the future + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DATE, 1); + claims.setIssuedAt(cal.getTimeInMillis() / 1000L); + + JwtToken token = new JwtToken(claims); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertNotEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testNearFutureTokenFailure() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setAudiences(toList(address)); + + // Set the issued date to be in the near future + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.SECOND, 30); + claims.setIssuedAt(cal.getTimeInMillis() / 1000L); + + JwtToken token = new JwtToken(claims); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertNotEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testNearFutureTokenSuccess() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwtnearfuture/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setAudiences(toList(address)); + + // Set the issued date to be in the near future + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.SECOND, 30); + claims.setIssuedAt(cal.getTimeInMillis() / 1000L); + + JwtToken token = new JwtToken(claims); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testNotBeforeFailure() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setAudiences(toList(address)); + + // Set the issued date to be in the near future + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.SECOND, 30); + claims.setIssuedAt(new Date().getTime() / 1000L); + claims.setNotBefore(cal.getTimeInMillis() / 1000L); + + JwtToken token = new JwtToken(claims); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertNotEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testNotBeforeSuccess() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwtnearfuture/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setAudiences(toList(address)); + + // Set the issued date to be in the near future + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.SECOND, 30); + claims.setIssuedAt(new Date().getTime() / 1000L); + claims.setNotBefore(cal.getTimeInMillis() / 1000L); + + JwtToken token = new JwtToken(claims); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testSetClaimsDirectly() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setIssuedAt(new Date().getTime() / 1000L); + claims.setAudiences(toList(address)); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_CLAIMS, claims); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testBadAudience() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setIssuedAt(new Date().getTime() / 1000L); + String badAddress = "https://localhost:" + PORT + "/badunsignedjwt/bookstore/books"; + claims.setAudiences(toList(badAddress)); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_CLAIMS, claims); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertNotEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testNoAudience() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setIssuedAt(new Date().getTime() / 1000L); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_CLAIMS, claims); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertNotEquals(response.getStatus(), 200); + } + + @org.junit.Test + public void testMultipleAudiences() throws Exception { + + URL busFile = JWTPropertiesTest.class.getResource("client.xml"); + + List providers = new ArrayList(); + providers.add(new JacksonJsonProvider()); + providers.add(new JwtAuthenticationClientFilter()); + + String address = "https://localhost:" + PORT + "/unsignedjwt/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + + // Create the JWT Token + JwtClaims claims = new JwtClaims(); + claims.setSubject("alice"); + claims.setIssuer("DoubleItSTSIssuer"); + claims.setIssuedAt(new Date().getTime() / 1000L); + + String badAddress = "https://localhost:" + PORT + "/badunsignedjwt/bookstore/books"; + List audiences = new ArrayList(); + audiences.add(address); + audiences.add(badAddress); + claims.setAudiences(audiences); + + Map properties = new HashMap(); + properties.put("rs.security.signature.algorithm", "none"); + properties.put(JwtConstants.JWT_CLAIMS, claims); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertEquals(response.getStatus(), 200); + } + + private List toList(String address) { + return Collections.singletonList(address); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e9e7ff13/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/properties-server.xml ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/properties-server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/properties-server.xml new file mode 100644 index 0000000..7c286db --- /dev/null +++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/properties-server.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +