Search in sources :

Example 6 with MessageSigner

use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.

the class JAXRSHTTPSignatureTest method testMultipleHeaderConcatenation.

@Test
public void testMultipleHeaderConcatenation() 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("custom", "(request-target)");
    MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id", headerList);
    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");
    client.header("custom", "someval, someval2");
    Response response = client.post(new Book("CXF", 126L));
    assertEquals(200, response.getStatus());
    Book returnedBook = response.readEntity(Book.class);
    assertEquals(126L, returnedBook.getId());
}
Also used : Response(javax.ws.rs.core.Response) MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) PrivateKey(java.security.PrivateKey) CreateSignatureInterceptor(org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor) Book(org.apache.cxf.systest.jaxrs.security.Book) KeyStore(java.security.KeyStore) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 7 with MessageSigner

use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.

the class JAXRSHTTPSignatureTest method testIncorrectDigest.

@Test
public void testIncorrectDigest() throws Exception {
    URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
    CreateDigestTestInterceptor signatureFilter = new CreateDigestTestInterceptor();
    signatureFilter.setChangeDigestValue(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());
}
Also used : Response(javax.ws.rs.core.Response) MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) PrivateKey(java.security.PrivateKey) Book(org.apache.cxf.systest.jaxrs.security.Book) KeyStore(java.security.KeyStore) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 8 with MessageSigner

use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.

the class JAXRSHTTPSignatureTest method testHttpSignatureEmptyResponseProps.

@Test
public void testHttpSignatureEmptyResponseProps() 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();
    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");
    Map<String, Object> properties = new HashMap<>();
    properties.put("rs.security.signature.in.properties", "org/apache/cxf/systest/jaxrs/security/httpsignature/bob.httpsig.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    Response response = client.post(new Book("CXF", 126L));
    assertEquals(204, response.getStatus());
}
Also used : MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) PrivateKey(java.security.PrivateKey) HashMap(java.util.HashMap) KeyStore(java.security.KeyStore) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Response(javax.ws.rs.core.Response) CreateSignatureInterceptor(org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor) Book(org.apache.cxf.systest.jaxrs.security.Book) VerifySignatureClientFilter(org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter) Test(org.junit.Test)

Example 9 with MessageSigner

use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.

the class JAXRSHTTPSignatureTest method testEmptySignatureValue.

@Test
public void testEmptySignatureValue() throws Exception {
    URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
    ClientTestFilter signatureFilter = new ClientTestFilter();
    signatureFilter.setEmptySignatureValue(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());
}
Also used : Response(javax.ws.rs.core.Response) MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) PrivateKey(java.security.PrivateKey) Book(org.apache.cxf.systest.jaxrs.security.Book) KeyStore(java.security.KeyStore) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 10 with MessageSigner

use of org.apache.cxf.rs.security.httpsignature.MessageSigner in project cxf by apache.

the class JAXRSHTTPSignatureTest method testHttpSignatureGET.

@Test
public void testHttpSignatureGET() 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.path("/126").get();
    assertEquals(200, response.getStatus());
    Book returnedBook = response.readEntity(Book.class);
    assertEquals(123L, returnedBook.getId());
    String address2 = "http://localhost:" + PORT + "/httpsigrequired/bookstore/books";
    client = WebClient.create(address2, Collections.singletonList(signatureFilter), busFile.toString());
    client.type("application/xml").accept("application/xml");
    response = client.path("/126").get();
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) PrivateKey(java.security.PrivateKey) CreateSignatureInterceptor(org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor) Book(org.apache.cxf.systest.jaxrs.security.Book) KeyStore(java.security.KeyStore) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Aggregations

MessageSigner (org.apache.cxf.rs.security.httpsignature.MessageSigner)30 URL (java.net.URL)29 Response (javax.ws.rs.core.Response)29 WebClient (org.apache.cxf.jaxrs.client.WebClient)29 Book (org.apache.cxf.systest.jaxrs.security.Book)29 Test (org.junit.Test)29 KeyStore (java.security.KeyStore)28 PrivateKey (java.security.PrivateKey)28 CreateSignatureInterceptor (org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor)20 VerifySignatureClientFilter (org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter)5 MessageVerifier (org.apache.cxf.rs.security.httpsignature.MessageVerifier)4 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 KeyPair (java.security.KeyPair)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1