use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureNoRequestTarget.
@Test
public void testHttpSignatureNoRequestTarget() 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);
List<String> headerList = Arrays.asList("accept");
MessageSigner messageSigner = new MessageSigner("rsa-sha512", keyId -> privateKey, "alice-key-id", headerList);
signatureFilter.setMessageSigner(messageSigner);
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");
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.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureRsaSha512ServiceProperties.
@Test
public void testHttpSignatureRsaSha512ServiceProperties() 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 + "/httpsigrsasha512props/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.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureResponseServiceProperties.
@Test
public void testHttpSignatureResponseServiceProperties() 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 + "/httpsigresponseprops/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.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testHttpSignatureEmptyResponse.
@Test
public void testHttpSignatureEmptyResponse() 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 + "/httpsigresponse/bookstore/booksnoresp";
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(204, response.getStatus());
}
use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.
the class JAXRSHTTPSignatureTest method testChangedSignatureValue.
@Test
public void testChangedSignatureValue() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
ClientTestFilter signatureFilter = new ClientTestFilter();
signatureFilter.setChangeSignatureValue(true);
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(400, response.getStatus());
}
Aggregations