use of org.apache.coheigea.cxf.jaxrs.json.common.Number in project testcases by coheigea.
the class JWTEncryptedTest method testSignedEncryptedToken.
@org.junit.Test
public void testSignedEncryptedToken() throws Exception {
URL busFile = JWETest.class.getResource("cxf-client.xml");
List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJsonProvider());
JwtAuthenticationClientFilter jwtFilter = new JwtAuthenticationClientFilter();
jwtFilter.setJwsRequired(true);
jwtFilter.setJweRequired(true);
providers.add(jwtFilter);
String address = "http://localhost:" + PORT2 + "/doubleit/services";
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(Collections.singletonList(address));
JwtToken token = new JwtToken(claims);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("rs.security.signature.out.properties", "clientKeystore.properties");
properties.put("rs.security.encryption.properties", "clientEncKeystore.properties");
properties.put(JwtConstants.JWT_TOKEN, token);
WebClient.getConfig(client).getRequestContext().putAll(properties);
Number numberToDouble = new Number();
numberToDouble.setDescription("This is the number to double");
numberToDouble.setNumber(25);
Response response = client.post(numberToDouble);
assertEquals(response.getStatus(), 200);
assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
use of org.apache.coheigea.cxf.jaxrs.json.common.Number in project testcases by coheigea.
the class JWTEncryptedTest method testEncryptedClaims.
@org.junit.Test
public void testEncryptedClaims() throws Exception {
URL busFile = JWETest.class.getResource("cxf-client.xml");
List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJsonProvider());
JwtAuthenticationClientFilter jwtFilter = new JwtAuthenticationClientFilter();
jwtFilter.setJwsRequired(false);
jwtFilter.setJweRequired(true);
providers.add(jwtFilter);
String address = "http://localhost:" + PORT + "/doubleit/services";
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(Collections.singletonList(address));
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("rs.security.encryption.properties", "clientEncKeystore.properties");
properties.put(JwtConstants.JWT_CLAIMS, claims);
WebClient.getConfig(client).getRequestContext().putAll(properties);
Number numberToDouble = new Number();
numberToDouble.setDescription("This is the number to double");
numberToDouble.setNumber(25);
Response response = client.post(numberToDouble);
assertEquals(response.getStatus(), 200);
assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
use of org.apache.coheigea.cxf.jaxrs.json.common.Number in project testcases by coheigea.
the class DoubleItJWTAuthenticationService method doubleIt.
@POST
@Produces("application/json")
@Consumes("application/json")
public Number doubleIt(Number numberToDouble) {
// Check the context was set up correctly etc.
Assert.assertNotNull(jaxrsContext.getSecurityContext().getUserPrincipal());
JwtTokenSecurityContext securityContext = (JwtTokenSecurityContext) jaxrsContext.get(SecurityContext.class.getName());
Assert.assertNotNull(securityContext);
Assert.assertEquals("DoubleItSTSIssuer", securityContext.getToken().getClaim(JwtConstants.CLAIM_ISSUER));
Number newNumber = new Number();
newNumber.setDescription(numberToDouble.getDescription());
newNumber.setNumber(numberToDouble.getNumber() * 2);
return newNumber;
}
use of org.apache.coheigea.cxf.jaxrs.json.common.Number in project testcases by coheigea.
the class DoubleItAuthenticationService method doubleIt.
@POST
@Produces("application/json")
@Consumes("application/json")
public Number doubleIt(Number numberToDouble) {
// Check the context was set up correctly etc.
Assert.assertNotNull(jaxrsContext.getSecurityContext().getUserPrincipal());
Number newNumber = new Number();
newNumber.setDescription(numberToDouble.getDescription());
newNumber.setNumber(numberToDouble.getNumber() * 2);
return newNumber;
}
use of org.apache.coheigea.cxf.jaxrs.json.common.Number in project testcases by coheigea.
the class JWETest method testEncryptionCertificateSha1Test.
// Include the cert digest in the "x5t" header
@org.junit.Test
public void testEncryptionCertificateSha1Test() throws Exception {
URL busFile = JWETest.class.getResource("cxf-client.xml");
List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJsonProvider());
providers.add(new JweWriterInterceptor());
String address = "http://localhost:" + PORT6 + "/doubleit/services";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/json").accept("application/json");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("rs.security.keystore.type", "jks");
properties.put("rs.security.keystore.password", "sspass");
properties.put("rs.security.keystore.alias", "myservicekey");
properties.put("rs.security.keystore.file", "servicestore.jks");
properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
properties.put("rs.security.encryption.content.algorithm", "A128CBC-HS256");
properties.put("rs.security.encryption.include.cert.sha1", "true");
WebClient.getConfig(client).getRequestContext().putAll(properties);
Number numberToDouble = new Number();
numberToDouble.setDescription("This is the number to double");
numberToDouble.setNumber(25);
Response response = client.post(numberToDouble);
assertEquals(response.getStatus(), 200);
assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Aggregations