Search in sources :

Example 6 with VerifySignatureClientFilter

use of org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter 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
    }
}
Also used : 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) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 7 with VerifySignatureClientFilter

use of org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter 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());
}
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)

Aggregations

URL (java.net.URL)7 WebClient (org.apache.cxf.jaxrs.client.WebClient)7 CreateSignatureInterceptor (org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor)7 VerifySignatureClientFilter (org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureClientFilter)7 Book (org.apache.cxf.systest.jaxrs.security.Book)7 Test (org.junit.Test)7 Response (javax.ws.rs.core.Response)6 KeyStore (java.security.KeyStore)5 PrivateKey (java.security.PrivateKey)5 MessageSigner (org.apache.cxf.rs.security.httpsignature.MessageSigner)5 ArrayList (java.util.ArrayList)4 MessageVerifier (org.apache.cxf.rs.security.httpsignature.MessageVerifier)4 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2