Search in sources :

Example 1 with JwsWriterInterceptor

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

the class JWSSignatureTest method testPSSignatureCompact.

@org.junit.Test
public void testPSSignatureCompact() throws Exception {
    try {
        Security.addProvider(new BouncyCastleProvider());
        URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
        List<Object> providers = new ArrayList<Object>();
        providers.add(new JacksonJsonProvider());
        JwsWriterInterceptor writer = new JwsWriterInterceptor();
        providers.add(writer);
        String address = "http://localhost:" + PORT4 + "/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.keystore.type", "jks");
        properties.put("rs.security.keystore.password", "cspass");
        properties.put("rs.security.keystore.alias", "myclientkey");
        properties.put("rs.security.keystore.file", "clientstore.jks");
        properties.put("rs.security.key.password", "ckpass");
        properties.put("rs.security.signature.algorithm", "PS256");
        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);
    } finally {
        Security.removeProvider(BouncyCastleProvider.class.getName());
    }
}
Also used : 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) Response(javax.ws.rs.core.Response) Number(org.apache.coheigea.cxf.jaxrs.json.common.Number) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 2 with JwsWriterInterceptor

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

the class JWSSignatureTest method testSignatureCompactDynamicProperties.

@org.junit.Test
public void testSignatureCompactDynamicProperties() throws Exception {
    URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
    List<Object> providers = new ArrayList<Object>();
    providers.add(new JacksonJsonProvider());
    JwsWriterInterceptor writer = new JwsWriterInterceptor();
    providers.add(writer);
    String address = "http://localhost:" + PORT2 + "/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.keystore.type", "jks");
    properties.put("rs.security.keystore.password", "cspass");
    properties.put("rs.security.keystore.alias", "myclientkey");
    properties.put("rs.security.keystore.file", "clientstore.jks");
    properties.put("rs.security.key.password", "ckpass");
    properties.put("rs.security.signature.algorithm", "RS256");
    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) HashMap(java.util.HashMap) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 3 with JwsWriterInterceptor

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

the class JWSSignatureTest method testImposterSignature.

@org.junit.Test
public void testImposterSignature() throws Exception {
    URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
    List<Object> providers = new ArrayList<Object>();
    providers.add(new JacksonJsonProvider());
    JwsWriterInterceptor writer = new JwsWriterInterceptor();
    providers.add(writer);
    String address = "http://localhost:" + PORT2 + "/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.keystore.type", "jks");
    properties.put("rs.security.keystore.password", "ispass");
    properties.put("rs.security.keystore.alias", "imposter");
    properties.put("rs.security.keystore.file", "imposter.jks");
    properties.put("rs.security.key.password", "ikpass");
    properties.put("rs.security.signature.algorithm", "RS256");
    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);
    assertNotEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) Number(org.apache.coheigea.cxf.jaxrs.json.common.Number) HashMap(java.util.HashMap) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 4 with JwsWriterInterceptor

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

the class JWSSignatureTest method testSigningXMLPayload.

@org.junit.Test
public void testSigningXMLPayload() throws Exception {
    URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
    List<Object> providers = new ArrayList<Object>();
    providers.add(new JacksonJsonProvider());
    JwsWriterInterceptor writer = new JwsWriterInterceptor();
    providers.add(writer);
    String address = "http://localhost:" + PORT6 + "/doubleit/services";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/xml").accept("application/xml");
    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) HashMap(java.util.HashMap) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 5 with JwsWriterInterceptor

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

the class JWSSignatureTest method testSignatureCertificateTest.

// Include the cert in the "x5c" header
@org.junit.Test
public void testSignatureCertificateTest() throws Exception {
    URL busFile = JWSSignatureTest.class.getResource("cxf-client.xml");
    List<Object> providers = new ArrayList<Object>();
    providers.add(new JacksonJsonProvider());
    JwsWriterInterceptor writer = new JwsWriterInterceptor();
    providers.add(writer);
    String address = "http://localhost:" + PORT7 + "/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.keystore.type", "jks");
    properties.put("rs.security.keystore.password", "cspass");
    properties.put("rs.security.keystore.alias", "myclientkey");
    properties.put("rs.security.keystore.file", "clientstore.jks");
    properties.put("rs.security.key.password", "ckpass");
    properties.put("rs.security.signature.algorithm", "RS256");
    properties.put("rs.security.signature.include.cert", "true");
    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) HashMap(java.util.HashMap) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ArrayList(java.util.ArrayList) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Aggregations

URL (java.net.URL)33 JwsWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)33 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)27 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)27 Response (javax.ws.rs.core.Response)27 WebClient (org.apache.cxf.jaxrs.client.WebClient)27 Book (org.apache.cxf.systest.jaxrs.security.Book)17 Number (org.apache.coheigea.cxf.jaxrs.json.common.Number)10 LinkedList (java.util.LinkedList)6 Bus (org.apache.cxf.Bus)6 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)6 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)6 JwsClientResponseFilter (org.apache.cxf.rs.security.jose.jaxrs.JwsClientResponseFilter)5 HashSet (java.util.HashSet)4 JweWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor)4 BookStore (org.apache.cxf.systest.jaxrs.security.jose.BookStore)4 PrivateKeyPasswordProvider (org.apache.cxf.rt.security.rs.PrivateKeyPasswordProvider)3 Test (org.junit.Test)3 JweClientResponseFilter (org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter)2