use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project cxf by apache.
the class JweJwsReferenceTest method testSignatureIncludeCert.
//
// Signature tests
//
@org.junit.Test
public void testSignatureIncludeCert() throws Exception {
URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JwsWriterInterceptor());
String address = "http://localhost:" + PORT + "/jwsincludecert/bookstore/books";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/json").accept("application/json");
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.keystore.type", "jks");
properties.put("rs.security.keystore.alias", "alice");
properties.put("rs.security.keystore.password", "password");
properties.put("rs.security.key.password", "password");
properties.put("rs.security.keystore.file", "keys/alice.jks");
WebClient.getConfig(client).getRequestContext().putAll(properties);
// First test that it fails without adding a cert (reference). This is because
// the service side does not have an alias configured
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
// Now it should work
properties.put("rs.security.signature.include.cert", "true");
WebClient.getConfig(client).getRequestContext().putAll(properties);
response = client.post(new Book("book", 123L));
assertEquals(response.getStatus(), 200);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project cxf by apache.
the class JweJwsReferenceTest method testSignatureIncludeCertNegativeTest.
@org.junit.Test
public void testSignatureIncludeCertNegativeTest() throws Exception {
URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JwsWriterInterceptor());
String address = "http://localhost:" + PORT + "/jwsincludecert/bookstore/books";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/json").accept("application/json");
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.keystore.type", "jks");
properties.put("rs.security.keystore.alias", "morpit");
properties.put("rs.security.keystore.password", "password");
properties.put("rs.security.key.password", "password");
properties.put("rs.security.keystore.file", "keys/Morpit.jks");
properties.put("rs.security.signature.include.cert", "true");
WebClient.getConfig(client).getRequestContext().putAll(properties);
// Failure expected as we are signing using a cert not trusted by cxfca.jks
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project testcases by coheigea.
the class JWEJWSTest method testEncryptionSignatureCompactProperties.
@org.junit.Test
public void testEncryptionSignatureCompactProperties() throws Exception {
URL busFile = JWEJWSTest.class.getResource("cxf-client.xml");
List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJsonProvider());
providers.add(new JweWriterInterceptor());
providers.add(new JwsWriterInterceptor());
String address = "http://localhost:" + PORT2 + "/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.encryption.properties", "clientEncKeystore.properties");
properties.put("rs.security.signature.out.properties", "clientKeystore.properties");
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.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project testcases by coheigea.
the class JWSSignatureTest method testSignatureCertificateSha1Test.
// Include the cert digest in the "x5t" header
@org.junit.Test
public void testSignatureCertificateSha1Test() throws Exception {
URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJsonProvider());
JwsWriterInterceptor writer = new JwsWriterInterceptor();
providers.add(writer);
String address = "http://localhost:" + PORT8 + "/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", "cspass");
properties.put("rs.security.keystore.alias", "myclientkey");
properties.put("rs.security.keystore.file", "clientstore.jks");
properties.put("rs.security.key.password", "ckpass");
properties.put("rs.security.signature.algorithm", "RS256");
properties.put("rs.security.signature.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);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project testcases by coheigea.
the class JWSSignatureTest method testSignatureCompact.
@org.junit.Test
public void testSignatureCompact() throws Exception {
URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJsonProvider());
JwsWriterInterceptor writer = new JwsWriterInterceptor();
providers.add(writer);
String address = "http://localhost:" + PORT2 + "/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.signature.out.properties", "clientKeystore.properties");
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