use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureDigestSHA512.
@Test
public void testHttpSignatureDigestSHA512() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor();
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id");
signatureFilter.setMessageSigner(messageSigner);
String address = "http://localhost:" + PORT + "/httpsig/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.http.signature.digest.algorithm", "SHA-512");
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("CXF", 126L));
assertEquals(200, response.getStatus());
Book returnedBook = response.readEntity(Book.class);
assertEquals(126L, returnedBook.getId());
}
use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureSignaturePropertiesRsaSha512.
@Test
public void testHttpSignatureSignaturePropertiesRsaSha512() {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor();
String address = "http://localhost:" + PORT + "/httpsigrsasha512/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.keystore.alias", "alice");
properties.put("rs.security.keystore.password", "password");
properties.put("rs.security.keystore.file", "keys/alice.jks");
properties.put("rs.security.key.password", "password");
properties.put("rs.security.signature.algorithm", "rsa-sha512");
properties.put("rs.security.http.signature.key.id", "alice-key-id");
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("CXF", 126L));
assertEquals(200, response.getStatus());
Book returnedBook = response.readEntity(Book.class);
assertEquals(126L, returnedBook.getId());
}
use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureResponse.
@Test
public void testHttpSignatureResponse() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor();
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id");
signatureFilter.setMessageSigner(messageSigner);
VerifySignatureClientFilter signatureResponseFilter = new VerifySignatureClientFilter();
MessageVerifier messageVerifier = new MessageVerifier(new CustomPublicKeyProvider());
signatureResponseFilter.setMessageVerifier(messageVerifier);
List<Object> providers = new ArrayList<>();
providers.add(signatureFilter);
providers.add(signatureResponseFilter);
String address = "http://localhost:" + PORT + "/httpsigresponse/bookstore/books";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/xml").accept("application/xml");
Response response = client.post(new Book("CXF", 126L));
assertEquals(200, response.getStatus());
Book returnedBook = response.readEntity(Book.class);
assertEquals(126L, returnedBook.getId());
}
use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor in project cxf by apache.
the class JAXRSHTTPSignatureTest method testMissingDigestHeader.
@Test
public void testMissingDigestHeader() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor();
signatureFilter.setAddDigest(false);
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
List<String> headerList = Arrays.asList("accept", "(request-target)");
MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id", headerList);
signatureFilter.setMessageSigner(messageSigner);
String address = "http://localhost:" + PORT + "/httpsigprops/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Response response = client.post(new Book("CXF", 126L));
assertEquals(400, response.getStatus());
}
use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor in project cxf by apache.
the class JAXRSHTTPSignatureTest method testPropertiesWrongSignatureVerification.
@Test
public void testPropertiesWrongSignatureVerification() {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new CreateSignatureInterceptor());
providers.add(new VerifySignatureClientFilter());
String address = "http://localhost:" + PORT + "/httpsigresponse/bookstore/books";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/xml").accept("application/xml");
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.signature.out.properties", "org/apache/cxf/systest/jaxrs/security/httpsignature/alice.httpsig.properties");
properties.put("rs.security.signature.in.properties", "org/apache/cxf/systest/jaxrs/security/httpsignature/alice.httpsig.properties");
WebClient.getConfig(client).getRequestContext().putAll(properties);
try {
client.post(new Book("CXF", 126L));
fail("Failure expected on the wrong signature verification keystore");
} catch (Exception ex) {
// expected
}
}
Aggregations