use of org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter in project cxf by apache.
the class JWTPropertiesTest method testNoAudience.
@org.junit.Test
public void testNoAudience() throws Exception {
URL busFile = JWTPropertiesTest.class.getResource("client.xml");
List<Object> 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");
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
claims.setIssuedAt(now.toEpochSecond());
Map<String, Object> 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);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter in project cxf by apache.
the class JWTPropertiesTest method testMultipleAudiences.
@org.junit.Test
public void testMultipleAudiences() throws Exception {
URL busFile = JWTPropertiesTest.class.getResource("client.xml");
List<Object> 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");
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
claims.setIssuedAt(now.toEpochSecond());
String badAddress = "https://localhost:" + PORT + "/badunsignedjwt/bookstore/books";
List<String> audiences = new ArrayList<>();
audiences.add(address);
audiences.add(badAddress);
claims.setAudiences(audiences);
Map<String, Object> 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);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter in project cxf by apache.
the class JWTAlgorithmTest method testBadSigningKey.
@org.junit.Test
public void testBadSigningKey() throws Exception {
URL busFile = JWTAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JwtAuthenticationClientFilter());
String address = "https://localhost:" + PORT + "/signedjwt/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(Instant.now().getEpochSecond());
claims.setAudiences(toList(address));
JwtToken token = new JwtToken(claims);
Map<String, Object> 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", "keys/alice.jks");
properties.put("rs.security.signature.algorithm", "RS256");
properties.put(JwtConstants.JWT_TOKEN, token);
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter in project cxf by apache.
the class JWTAlgorithmTest method testWrongContentEncryptionAlgorithm.
@org.junit.Test
public void testWrongContentEncryptionAlgorithm() throws Exception {
if (!SecurityTestUtil.checkUnrestrictedPoliciesInstalled()) {
return;
}
URL busFile = JWTAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
JwtAuthenticationClientFilter clientFilter = new JwtAuthenticationClientFilter();
clientFilter.setJwsRequired(false);
clientFilter.setJweRequired(true);
providers.add(clientFilter);
String address = "https://localhost:" + PORT + "/encryptedjwt/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(Instant.now().getEpochSecond());
claims.setAudiences(toList(address));
JwtToken token = new JwtToken(claims);
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.keystore.type", "jwk");
properties.put("rs.security.keystore.alias", "2011-04-29");
properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt");
properties.put("rs.security.encryption.content.algorithm", "A128GCM");
properties.put("rs.security.encryption.content.algorithm", "A192GCM");
properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
properties.put(JwtConstants.JWT_TOKEN, token);
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter in project cxf by apache.
the class JWTAlgorithmTest method testSmallSignatureKeySize.
// 1024 bits not allowed with RSA according to the spec
@org.junit.Test
public void testSmallSignatureKeySize() throws Exception {
URL busFile = JWTAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JwtAuthenticationClientFilter());
String address = "https://localhost:" + PORT + "/signedjwt/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(Instant.now().getEpochSecond());
claims.setAudiences(toList(address));
JwtToken token = new JwtToken(claims);
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.keystore.type", "jks");
properties.put("rs.security.keystore.alias", "smallkey");
properties.put("rs.security.keystore.password", "security");
properties.put("rs.security.key.password", "security");
properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/smallkeysize.jks");
properties.put("rs.security.signature.algorithm", "RS256");
properties.put(JwtConstants.JWT_TOKEN, token);
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
Aggregations