use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureProperties.
@Test
public void testHttpSignatureProperties() {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor();
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.signature.properties", "org/apache/cxf/systest/jaxrs/security/httpsignature/alice.httpsig.properties");
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 testHttpSignatureDigestResponse.
@Test
public void testHttpSignatureDigestResponse() 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);
String address = "http://localhost:" + PORT + "/httpsigrequired/bookstore/books";
WebClient client = WebClient.create(address, Arrays.asList(signatureFilter, signatureResponseFilter), 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());
String address2 = "http://localhost:" + PORT + "/httpsig/bookstore/books";
client = WebClient.create(address2, Arrays.asList(signatureFilter, signatureResponseFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
try {
client.post(new Book("CXF", 126L));
fail("Failure expected on no digest");
} catch (Exception ex) {
// expected
}
}
use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureServiceProperties.
@Test
public void testHttpSignatureServiceProperties() 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 + "/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(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 testHttpSignature.
@Test
public void testHttpSignature() 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");
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 testNonMatchingSignatureAlgorithm.
//
// Negative tests
//
@Test
public void testNonMatchingSignatureAlgorithm() 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("rsa-sha512", 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");
Response response = client.post(new Book("CXF", 126L));
assertEquals(400, response.getStatus());
}
Aggregations