Search in sources :

Example 16 with JweWriterInterceptor

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

the class JAXRSJweJwsTest method createJweBookStore.

private BookStore createJweBookStore(String address, 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());
    if (mbProviders != null) {
        providers.addAll(mbProviders);
    }
    bean.setProviders(providers);
    bean.getProperties(true).put("rs.security.encryption.out.properties", "org/apache/cxf/systest/jaxrs/security/bob.jwk.properties");
    bean.getProperties(true).put("rs.security.encryption.in.properties", "org/apache/cxf/systest/jaxrs/security/alice.jwk.properties");
    return bean.create(BookStore.class);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) JweClientResponseFilter(org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter) URL(java.net.URL) LinkedList(java.util.LinkedList)

Example 17 with JweWriterInterceptor

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

the class JAXRSJweJwsTest method testJweJwkAesWrap.

@Test
public void testJweJwkAesWrap() throws Exception {
    String address = "https://localhost:" + PORT + "/jwejwkaeswrap";
    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());
    bean.setProviders(providers);
    bean.getProperties(true).put("rs.security.encryption.properties", "org/apache/cxf/systest/jaxrs/security/secret.jwk.properties");
    bean.getProperties(true).put("jose.debug", true);
    BookStore bs = bean.create(BookStore.class);
    String text = bs.echoText("book");
    assertEquals("book", text);
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.security.jose.BookStore) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) JweClientResponseFilter(org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter) URL(java.net.URL) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 18 with JweWriterInterceptor

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

the class JAXRSJwsJsonTest method testJweCompactJwsJsonBookBeanHmac.

@Test
public void testJweCompactJwsJsonBookBeanHmac() throws Exception {
    if (!SecurityTestUtil.checkUnrestrictedPoliciesInstalled()) {
        return;
    }
    String address = "https://localhost:" + PORT + "/jwejwsjsonhmac";
    List<?> extraProviders = Arrays.asList(new JacksonJsonProvider(), new JweWriterInterceptor(), new JweClientResponseFilter());
    String jwkStoreProperty = "org/apache/cxf/systest/jaxrs/security/secret.jwk.properties";
    Map<String, Object> props = new HashMap<>();
    props.put(JoseConstants.RSSEC_SIGNATURE_PROPS, jwkStoreProperty);
    props.put(JoseConstants.RSSEC_ENCRYPTION_PROPS, jwkStoreProperty);
    BookStore bs = createBookStore(address, props, extraProviders);
    Book book = bs.echoBook(new Book("book", 123L));
    assertEquals("book", book.getName());
    assertEquals(123L, book.getId());
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.security.jose.BookStore) HashMap(java.util.HashMap) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) JweClientResponseFilter(org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter) Book(org.apache.cxf.systest.jaxrs.security.Book) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Test(org.junit.Test)

Example 19 with JweWriterInterceptor

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

the class JweJwsAlgorithmTest method testEncryptionProperties.

// 
// Encryption tests
// 
@org.junit.Test
public void testEncryptionProperties() throws Exception {
    URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jweoaepgcm/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.encryption.properties", "org/apache/cxf/systest/jaxrs/security/bob.jwk.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    Response response = client.post(new Book("book", 123L));
    assertEquals(response.getStatus(), 200);
    Book returnedBook = response.readEntity(Book.class);
    assertEquals(returnedBook.getName(), "book");
    assertEquals(returnedBook.getId(), 123L);
}
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 20 with JweWriterInterceptor

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

the class JweJwsAlgorithmTest method testWrongContentEncryptionAlgorithm.

@org.junit.Test
public void testWrongContentEncryptionAlgorithm() throws Exception {
    if (!SecurityTestUtil.checkUnrestrictedPoliciesInstalled()) {
        return;
    }
    URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jweoaepgcm/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", "jwk");
    properties.put("rs.security.keystore.alias", "2011-04-29");
    properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt");
    properties.put("rs.security.encryption.content.algorithm", "A192GCM");
    properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    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)

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