Search in sources :

Example 6 with CreateSignatureInterceptor

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

the class JAXRSHTTPSignatureTest method testHttpSignatureResponseProperties.

@Test
public void testHttpSignatureResponseProperties() {
    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/bob.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());
}
Also used : Response(javax.ws.rs.core.Response) CreateSignatureInterceptor(org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor) HashMap(java.util.HashMap) Book(org.apache.cxf.systest.jaxrs.security.Book) ArrayList(java.util.ArrayList) VerifySignatureClientFilter(org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 7 with CreateSignatureInterceptor

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

the class JAXRSHTTPSignatureTest method testHttpSignatureSignSpecificHeaderProperties.

@Test
public void testHttpSignatureSignSpecificHeaderProperties() 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);
    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");
    List<String> headerList = Arrays.asList("accept", "(request-target)");
    properties.put("rs.security.http.signature.out.headers", headerList);
    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());
}
Also used : Response(javax.ws.rs.core.Response) PrivateKey(java.security.PrivateKey) CreateSignatureInterceptor(org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor) HashMap(java.util.HashMap) 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 CreateSignatureInterceptor

use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor 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());
}
Also used : MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) PrivateKey(java.security.PrivateKey) ArrayList(java.util.ArrayList) MessageVerifier(org.apache.cxf.rs.security.httpsignature.MessageVerifier) 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 CreateSignatureInterceptor

use of org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor 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());
}
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) MessageVerifier(org.apache.cxf.rs.security.httpsignature.MessageVerifier) VerifySignatureClientFilter(org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter) KeyStore(java.security.KeyStore) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 10 with CreateSignatureInterceptor

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

the class JAXRSHTTPSignatureTest method testHttpSignaturePropertiesPasswordProvider.

@Test
public void testHttpSignaturePropertiesPasswordProvider() {
    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.keystore.alias", "alice");
    properties.put("rs.security.keystore.password", "password");
    properties.put("rs.security.keystore.file", "keys/alice.jks");
    PrivateKeyPasswordProvider passwordProvider = storeProperties -> "password".toCharArray();
    properties.put("rs.security.key.password.provider", passwordProvider);
    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());
}
Also used : KeyPair(java.security.KeyPair) CreateSignatureInterceptor(org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor) Arrays(java.util.Arrays) MessageDigestInputStream(org.apache.cxf.common.util.MessageDigestInputStream) Provider(javax.ws.rs.ext.Provider) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) MessageDigest(java.security.MessageDigest) Priorities(javax.ws.rs.Priorities) HashMap(java.util.HashMap) ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) VerifySignatureClientFilter(org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter) Map(java.util.Map) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Assert.fail(org.junit.Assert.fail) OutputStream(java.io.OutputStream) KeyPairGenerator(java.security.KeyPairGenerator) ClientRequestContext(javax.ws.rs.client.ClientRequestContext) PrivateKeyPasswordProvider(org.apache.cxf.rt.security.rs.PrivateKeyPasswordProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertNotNull(org.junit.Assert.assertNotNull) IOUtils(org.apache.cxf.helpers.IOUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) KeyStore(java.security.KeyStore) Test(org.junit.Test) ClassLoaderUtils(org.apache.cxf.common.classloader.ClassLoaderUtils) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MessageVerifier(org.apache.cxf.rs.security.httpsignature.MessageVerifier) Objects(java.util.Objects) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) Priority(javax.annotation.Priority) Base64(java.util.Base64) List(java.util.List) Book(org.apache.cxf.systest.jaxrs.security.Book) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) Response(javax.ws.rs.core.Response) PrivateKey(java.security.PrivateKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Collections(java.util.Collections) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Assert.assertEquals(org.junit.Assert.assertEquals) Response(javax.ws.rs.core.Response) CreateSignatureInterceptor(org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor) HashMap(java.util.HashMap) Book(org.apache.cxf.systest.jaxrs.security.Book) WebClient(org.apache.cxf.jaxrs.client.WebClient) PrivateKeyPasswordProvider(org.apache.cxf.rt.security.rs.PrivateKeyPasswordProvider) URL(java.net.URL) Test(org.junit.Test)

Aggregations

CreateSignatureInterceptor (org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor)30 Test (org.junit.Test)30 URL (java.net.URL)27 WebClient (org.apache.cxf.jaxrs.client.WebClient)27 Book (org.apache.cxf.systest.jaxrs.security.Book)27 Response (javax.ws.rs.core.Response)26 KeyStore (java.security.KeyStore)22 PrivateKey (java.security.PrivateKey)22 MessageSigner (org.apache.cxf.rs.security.httpsignature.MessageSigner)21 HashMap (java.util.HashMap)9 VerifySignatureClientFilter (org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter)8 ArrayList (java.util.ArrayList)5 MessageVerifier (org.apache.cxf.rs.security.httpsignature.MessageVerifier)5 ClientRequestContext (javax.ws.rs.client.ClientRequestContext)4 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)3 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 Message (org.apache.cxf.message.Message)3 MessageImpl (org.apache.cxf.message.MessageImpl)3