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: Adding JWT tests
Date Thu, 03 Dec 2015 14:47:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/master c352e1c56 -> a056d558c


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/9d6d9438
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/9d6d9438
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/9d6d9438

Branch: refs/heads/master
Commit: 9d6d9438c85b46b89510362dba89d85b8aa3796b
Parents: c352e1c
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Dec 3 14:47:00 2015 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Dec 3 14:47:14 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/9d6d9438/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/9d6d9438/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 1af1b31..e80a2bf 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
@@ -112,10 +112,6 @@ public class JWTAlgorithmTest extends AbstractBusClientServerTestBase
{
         assertEquals(returnedBook.getId(), 123L);
     }
     
-    private List<String> toList(String address) {
-        return Collections.singletonList(address);
-    }
-
     @org.junit.Test
     public void testEncryptionDynamic() throws Exception {
 
@@ -626,4 +622,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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<String> toList(String address) {
+        return Collections.singletonList(address);
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/9d6d9438/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<String> 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<String> toList(String address) {
+        return Collections.singletonList(address);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/9d6d9438/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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String, Object> properties = new HashMap<String, Object>();
+        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<Object> providers = new ArrayList<Object>();
+        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<String> audiences = new ArrayList<String>();
+        audiences.add(address);
+        audiences.add(badAddress);
+        claims.setAudiences(audiences);
+        
+        Map<String, Object> properties = new HashMap<String, Object>();
+        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<String> toList(String address) {
+        return Collections.singletonList(address);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/9d6d9438/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 @@
+<?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:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xsi:schemaLocation="         http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd         http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://www.springframework.org/schema/beans                 http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/transports/http/configuration         http://cxf.apache.org/schemas/configuration/http-conf.xsd
        http://cxf.apache.org/transports/http-jetty/configuration   http://cxf.apache.org/schemas/configuration/http-jetty.xsd
        http://cxf.apache.org/configuration/security    
             http://cxf.apache.org/schemas/configuration/security.xsd         ">
+    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+    <cxf:bus>
+        <cxf:features>
+            <cxf:logging/>
+        </cxf:features>
+    </cxf:bus>
+    <httpj:engine-factory id="port-9095-tls-config">
+        <httpj:engine port="${testutil.ports.jaxrs-jwt-properties}">
+            <httpj:tlsServerParameters>
+                <sec:keyManagers keyPassword="password">
+                    <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Bethal.jks"/>
+                </sec:keyManagers>
+                <sec:trustManagers>
+                    <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/>
+                </sec:trustManagers>
+                <sec:clientAuthentication want="true" required="true"/>
+            </httpj:tlsServerParameters>
+        </httpj:engine>
+    </httpj:engine-factory>
+    
+    <bean id="serviceBean" class="org.apache.cxf.systest.jaxrs.security.jose.BookStore"/>
+    
+    <bean id="jwtSigFilter" class="org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationFilter"
/>
+    
+    <jaxrs:server address="https://localhost:${testutil.ports.jaxrs-jwt-properties}/unsignedjwt">
+        <jaxrs:serviceBeans>
+            <ref bean="serviceBean"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="jwtSigFilter"/>
+        </jaxrs:providers>
+        <jaxrs:properties>
+            <entry key="rs.security.signature.algorithm" value="none" />
+        </jaxrs:properties>
+    </jaxrs:server>
+    
+    <bean id="newfutureFilter" class="org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationFilter">
+       <property name="clockOffset" value="60" />
+    </bean>
+   
+    <jaxrs:server address="https://localhost:${testutil.ports.jaxrs-jwt-properties}/unsignedjwtnearfuture">
+        <jaxrs:serviceBeans>
+            <ref bean="serviceBean"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="newfutureFilter"/>
+        </jaxrs:providers>
+        <jaxrs:properties>
+            <entry key="rs.security.signature.algorithm" value="none" />
+        </jaxrs:properties>
+    </jaxrs:server>
+</beans>


Mime
View raw message