Search in sources :

Example 1 with JwsJsonWriterInterceptor

use of org.apache.cxf.rs.security.jose.jaxrs.JwsJsonWriterInterceptor in project testcases by coheigea.

the class JWEJWSTest method testEncryptionSignatureListProperties.

@org.junit.Test
public void testEncryptionSignatureListProperties() throws Exception {
    URL busFile = JWEJWSTest.class.getResource("cxf-client.xml");
    List<Object> providers = new ArrayList<Object>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    JwsJsonWriterInterceptor writer = new JwsJsonWriterInterceptor();
    writer.setUseJwsJsonOutputStream(true);
    providers.add(writer);
    String address = "http://localhost:" + PORT + "/doubleit/services";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("rs.security.encryption.properties", "clientEncKeystore.properties");
    properties.put("rs.security.signature.out.properties", "clientKeystore.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : JwsJsonWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsJsonWriterInterceptor) HashMap(java.util.HashMap) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Response(javax.ws.rs.core.Response) Number(org.apache.coheigea.cxf.jaxrs.json.common.Number)

Example 2 with JwsJsonWriterInterceptor

use of org.apache.cxf.rs.security.jose.jaxrs.JwsJsonWriterInterceptor in project testcases by coheigea.

the class JWSSignatureTest method testSignatureListProperties.

@org.junit.Test
public void testSignatureListProperties() throws Exception {
    URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
    List<Object> providers = new ArrayList<Object>();
    providers.add(new JacksonJsonProvider());
    JwsJsonWriterInterceptor writer = new JwsJsonWriterInterceptor();
    writer.setUseJwsJsonOutputStream(true);
    providers.add(writer);
    String address = "http://localhost:" + PORT + "/doubleit/services";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("rs.security.signature.out.properties", "clientKeystore.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : Response(javax.ws.rs.core.Response) Number(org.apache.coheigea.cxf.jaxrs.json.common.Number) JwsJsonWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsJsonWriterInterceptor) HashMap(java.util.HashMap) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 3 with JwsJsonWriterInterceptor

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

the class JAXRSJwsJsonTest method createBookStore.

private BookStore createBookStore(String address, Map<String, Object> mapProperties, List<?> extraProviders, boolean encodePayload) throws Exception {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAXRSJwsJsonTest.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<>();
    JwsJsonWriterInterceptor writer = new JwsJsonWriterInterceptor();
    writer.setUseJwsJsonOutputStream(true);
    writer.setEncodePayload(encodePayload);
    providers.add(writer);
    providers.add(new JwsJsonClientResponseFilter());
    if (extraProviders != null) {
        providers.addAll(extraProviders);
    }
    bean.setProviders(providers);
    bean.getProperties(true).putAll(mapProperties);
    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) JwsJsonWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsJsonWriterInterceptor) JwsJsonClientResponseFilter(org.apache.cxf.rs.security.jose.jaxrs.JwsJsonClientResponseFilter) URL(java.net.URL) LinkedList(java.util.LinkedList)

Aggregations

URL (java.net.URL)3 JwsJsonWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JwsJsonWriterInterceptor)3 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Response (javax.ws.rs.core.Response)2 Number (org.apache.coheigea.cxf.jaxrs.json.common.Number)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 LinkedList (java.util.LinkedList)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 JweWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor)1 JwsJsonClientResponseFilter (org.apache.cxf.rs.security.jose.jaxrs.JwsJsonClientResponseFilter)1