Repository: cxf Updated Branches: refs/heads/master 14a6764d4 -> 12e6397e3
Adding some HMAC JWT tests Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1c2bda5a Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1c2bda5a Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1c2bda5a Branch: refs/heads/master Commit: 1c2bda5ac3c040d75c746327dbb7bd41c7524451 Parents: 14a6764 Author: Colm O hEigeartaigh <cohei...@apache.org> Authored: Mon Jan 4 16:40:32 2016 +0000 Committer: Colm O hEigeartaigh <cohei...@apache.org> Committed: Mon Jan 4 16:45:00 2016 +0000 ---------------------------------------------------------------------- .../security/jose/jwt/JWTAlgorithmTest.java | 74 ++++++++++++++++++++ .../security/jose/jwt/algorithms-server.xml | 16 +++++ 2 files changed, 90 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/1c2bda5a/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 e80a2bf..d627de9 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 @@ -667,6 +667,80 @@ public class JWTAlgorithmTest extends AbstractBusClientServerTestBase { assertEquals(returnedBook.getId(), 123L); } + @org.junit.Test + public void testHMACSignature() 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 + "/hmacsignedjwt/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", "jwk"); + properties.put("rs.security.keystore.alias", "HMAC512Key"); + properties.put("rs.security.keystore.file", + "org/apache/cxf/systest/jaxrs/security/certs/jwkPrivateSet.txt"); + 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); + } + + @org.junit.Test + public void testBadHMACSignature() 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 + "/hmacsignedjwt/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", "jwk"); + properties.put("rs.security.keystore.alias", "HMACKey"); + properties.put("rs.security.keystore.file", + "org/apache/cxf/systest/jaxrs/security/certs/jwkPrivateSet.txt"); + properties.put(JwtConstants.JWT_TOKEN, token); + WebClient.getConfig(client).getRequestContext().putAll(properties); + + Response response = client.post(new Book("book", 123L)); + assertNotEquals(response.getStatus(), 200); + } + private List<String> toList(String address) { return Collections.singletonList(address); } http://git-wip-us.apache.org/repos/asf/cxf/blob/1c2bda5a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/algorithms-server.xml ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/algorithms-server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/algorithms-server.xml index 5e270ce..3e59c9f 100644 --- a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/algorithms-server.xml +++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jose/jwt/algorithms-server.xml @@ -154,4 +154,20 @@ under the License. </jaxrs:properties> </jaxrs:server> + <jaxrs:server address="https://localhost:${testutil.ports.jaxrs-jwt-algorithms}/hmacsignedjwt"> + <jaxrs:serviceBeans> + <ref bean="serviceBean"/> + </jaxrs:serviceBeans> + <jaxrs:providers> + <ref bean="jwtSigFilter"/> + </jaxrs:providers> + <jaxrs:properties> + <entry key="rs.security.keystore.type" value="jwk"/> + <entry key="rs.security.keystore.alias" value="HMAC512Key"/> + <entry key="rs.security.keystore.file" + value="org/apache/cxf/systest/jaxrs/security/certs/jwkPrivateSet.txt"/> + <entry key="rs.security.signature.algorithm" value="HS512"/> + </jaxrs:properties> + </jaxrs:server> + </beans>