Search in sources :

Example 11 with JweWriterInterceptor

use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.

the class JweJwsReferenceTest method testEncryptionIncludeCert.

@org.junit.Test
public void testEncryptionIncludeCert() throws Exception {
    URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jweincludecert/bookstore/books";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    Map<String, Object> properties = new HashMap<>();
    properties.put("rs.security.keystore.type", "jks");
    properties.put("rs.security.keystore.alias", "bob");
    properties.put("rs.security.keystore.password", "password");
    properties.put("rs.security.key.password", "password");
    properties.put("rs.security.keystore.file", "keys/bob.jks");
    properties.put("rs.security.encryption.content.algorithm", "A128GCM");
    properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    // First test that it fails without adding a cert (reference). This is because
    // the service side does not have an alias configured
    Response response = client.post(new Book("book", 123L));
    assertNotEquals(response.getStatus(), 200);
    // Now it should work
    properties.put("rs.security.encryption.include.cert", "true");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    response = client.post(new Book("book", 123L));
    assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) Book(org.apache.cxf.systest.jaxrs.security.Book) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 12 with JweWriterInterceptor

use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.

the class JweJwsReferenceTest method testEncryptionIncludeCertNegativeTest.

@org.junit.Test
public void testEncryptionIncludeCertNegativeTest() throws Exception {
    URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jweincludecert/bookstore/books";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    Map<String, Object> properties = new HashMap<>();
    properties.put("rs.security.keystore.type", "jks");
    properties.put("rs.security.keystore.alias", "alice");
    properties.put("rs.security.keystore.password", "password");
    properties.put("rs.security.key.password", "password");
    properties.put("rs.security.keystore.file", "keys/alice.jks");
    properties.put("rs.security.encryption.content.algorithm", "A128GCM");
    properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
    properties.put("rs.security.encryption.include.cert", "true");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    // Failure expected as we are encrypting to "alice" instead of "bob"
    Response response = client.post(new Book("book", 123L));
    assertNotEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) Book(org.apache.cxf.systest.jaxrs.security.Book) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 13 with JweWriterInterceptor

use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.

the class JweJwsReferenceTest method testEncryptionIncludeCertSha1.

@org.junit.Test
public void testEncryptionIncludeCertSha1() throws Exception {
    URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jweincludecert/bookstore/books";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    Map<String, Object> properties = new HashMap<>();
    properties.put("rs.security.keystore.type", "jks");
    properties.put("rs.security.keystore.alias", "bob");
    properties.put("rs.security.keystore.password", "password");
    properties.put("rs.security.key.password", "password");
    properties.put("rs.security.keystore.file", "keys/bob.jks");
    properties.put("rs.security.encryption.content.algorithm", "A128GCM");
    properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    // First test that it fails without adding a cert (reference). This is because
    // the service side does not have an alias configured
    Response response = client.post(new Book("book", 123L));
    assertNotEquals(response.getStatus(), 200);
    // Now it should work
    properties.put("rs.security.encryption.include.cert.sha1", "true");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    response = client.post(new Book("book", 123L));
    assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) Book(org.apache.cxf.systest.jaxrs.security.Book) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 14 with JweWriterInterceptor

use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.

the class JweJwsReferenceTest method testEncryptionIncludeCertSha1NegativeTest.

@org.junit.Test
public void testEncryptionIncludeCertSha1NegativeTest() throws Exception {
    URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jweincludecert/bookstore/books";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    Map<String, Object> properties = new HashMap<>();
    properties.put("rs.security.keystore.type", "jks");
    properties.put("rs.security.keystore.alias", "alice");
    properties.put("rs.security.keystore.password", "password");
    properties.put("rs.security.key.password", "password");
    properties.put("rs.security.keystore.file", "keys/alice.jks");
    properties.put("rs.security.encryption.content.algorithm", "A128GCM");
    properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
    properties.put("rs.security.encryption.include.cert.sha1", "true");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    // Failure expected as we are encrypting to "alice" instead of "bob"
    Response response = client.post(new Book("book", 123L));
    assertNotEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) Book(org.apache.cxf.systest.jaxrs.security.Book) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 15 with JweWriterInterceptor

use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.

the class JAXRSJweJwsTest method createJweJwsBookStore.

private BookStore createJweJwsBookStore(String address, JwsSignatureProvider jwsSigProvider, List<?> mbProviders) throws Exception {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAXRSJweJwsTest.class.getResource("client.xml");
    Bus springBus = bf.createBus(busFile.toString());
    bean.setBus(springBus);
    bean.setServiceClass(BookStore.class);
    bean.setAddress(address);
    List<Object> providers = new LinkedList<Object>();
    JweWriterInterceptor jweWriter = new JweWriterInterceptor();
    jweWriter.setUseJweOutputStream(true);
    providers.add(jweWriter);
    providers.add(new JweClientResponseFilter());
    JwsWriterInterceptor jwsWriter = new JwsWriterInterceptor();
    if (jwsSigProvider != null) {
        jwsWriter.setSignatureProvider(jwsSigProvider);
    }
    jwsWriter.setUseJwsOutputStream(true);
    providers.add(jwsWriter);
    providers.add(new JwsClientResponseFilter());
    if (mbProviders != null) {
        providers.addAll(mbProviders);
    }
    bean.setProviders(providers);
    bean.getProperties(true).put("rs.security.encryption.out.properties", SERVER_JWEJWS_PROPERTIES);
    bean.getProperties(true).put("rs.security.signature.out.properties", CLIENT_JWEJWS_PROPERTIES);
    bean.getProperties(true).put("rs.security.encryption.in.properties", CLIENT_JWEJWS_PROPERTIES);
    bean.getProperties(true).put("rs.security.signature.in.properties", SERVER_JWEJWS_PROPERTIES);
    PrivateKeyPasswordProvider provider = new PrivateKeyPasswordProviderImpl();
    bean.getProperties(true).put("rs.security.signature.key.password.provider", provider);
    bean.getProperties(true).put("rs.security.decryption.key.password.provider", provider);
    return bean.create(BookStore.class);
}
Also used : Bus(org.apache.cxf.Bus) JwsClientResponseFilter(org.apache.cxf.rs.security.jose.jaxrs.JwsClientResponseFilter) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) PrivateKeyPasswordProvider(org.apache.cxf.rs.security.jose.common.PrivateKeyPasswordProvider) URL(java.net.URL) LinkedList(java.util.LinkedList) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JweClientResponseFilter(org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)

Aggregations

JweWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor)22 URL (java.net.URL)21 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)15 HashMap (java.util.HashMap)15 Book (org.apache.cxf.systest.jaxrs.security.Book)15 ArrayList (java.util.ArrayList)14 Response (javax.ws.rs.core.Response)14 WebClient (org.apache.cxf.jaxrs.client.WebClient)14 JweClientResponseFilter (org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter)8 LinkedList (java.util.LinkedList)7 Bus (org.apache.cxf.Bus)7 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)7 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)7 BookStore (org.apache.cxf.systest.jaxrs.security.jose.BookStore)6 Test (org.junit.Test)5 PrivateKeyPasswordProvider (org.apache.cxf.rs.security.jose.common.PrivateKeyPasswordProvider)3 JwsClientResponseFilter (org.apache.cxf.rs.security.jose.jaxrs.JwsClientResponseFilter)2 JwsWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)2 AesCbcHmacJweDecryption (org.apache.cxf.rs.security.jose.jwe.AesCbcHmacJweDecryption)1 AesCbcHmacJweEncryption (org.apache.cxf.rs.security.jose.jwe.AesCbcHmacJweEncryption)1