Search in sources :

Example 21 with JwsWriterInterceptor

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

the class JweJwsReferenceTest method testSignatureIncludeCert.

// 
// Signature tests
// 
@org.junit.Test
public void testSignatureIncludeCert() throws Exception {
    URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JwsWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jwsincludecert/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");
    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.signature.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) Book(org.apache.cxf.systest.jaxrs.security.Book) 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 22 with JwsWriterInterceptor

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

the class JweJwsReferenceTest method testSignatureIncludeCertNegativeTest.

@org.junit.Test
public void testSignatureIncludeCertNegativeTest() throws Exception {
    URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JwsWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jwsincludecert/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", "morpit");
    properties.put("rs.security.keystore.password", "password");
    properties.put("rs.security.key.password", "password");
    properties.put("rs.security.keystore.file", "keys/Morpit.jks");
    properties.put("rs.security.signature.include.cert", "true");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    // Failure expected as we are signing using a cert not trusted by cxfca.jks
    Response response = client.post(new Book("book", 123L));
    assertNotEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) Book(org.apache.cxf.systest.jaxrs.security.Book) 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 23 with JwsWriterInterceptor

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

the class JWEJWSTest method testEncryptionSignatureCompactProperties.

@org.junit.Test
public void testEncryptionSignatureCompactProperties() throws Exception {
    URL busFile = JWEJWSTest.class.getResource("cxf-client.xml");
    List<Object> providers = new ArrayList<Object>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JweWriterInterceptor());
    providers.add(new JwsWriterInterceptor());
    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.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 : 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) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)

Example 24 with JwsWriterInterceptor

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

the class JWSSignatureTest method testSignatureCertificateSha1Test.

// Include the cert digest in the "x5t" header
@org.junit.Test
public void testSignatureCertificateSha1Test() 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:" + PORT8 + "/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.sha1", "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)

Example 25 with JwsWriterInterceptor

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

the class JWSSignatureTest method testSignatureCompact.

@org.junit.Test
public void testSignatureCompact() 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.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)

Aggregations

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