Search in sources :

Example 31 with JwsWriterInterceptor

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

the class JweJwsAlgorithmTest method testUnsignedTokenFailure.

@org.junit.Test
public void testUnsignedTokenFailure() throws Exception {
    URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    JwsWriterInterceptor writerInterceptor = new JwsWriterInterceptor();
    writerInterceptor.setSignatureProvider(new NoneJwsSignatureProvider());
    providers.add(writerInterceptor);
    String address = "http://localhost:" + PORT + "/jws/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/jwkPrivateSet.txt");
    properties.put("rs.security.signature.algorithm", "none");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    Response response = client.post(new Book("book", 123L));
    assertNotEquals(response.getStatus(), 200);
}
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) Book(org.apache.cxf.systest.jaxrs.security.Book) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor) NoneJwsSignatureProvider(org.apache.cxf.rs.security.jose.jws.NoneJwsSignatureProvider)

Example 32 with JwsWriterInterceptor

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

the class JweJwsAlgorithmTest method testWrongSignatureAlgorithmKeyIncluded.

@org.junit.Test
public void testWrongSignatureAlgorithmKeyIncluded() throws Exception {
    URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JwsWriterInterceptor());
    String address = "http://localhost:" + PORT + "/jws/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/jwkPrivateSet.txt");
    properties.put("rs.security.signature.algorithm", "PS256");
    properties.put("rs.security.signature.include.public.key", true);
    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) 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 33 with JwsWriterInterceptor

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

the class JwsHTTPHeaderTest method testSignCustomHeaderRequired.

@org.junit.Test
public void testSignCustomHeaderRequired() throws Exception {
    URL busFile = JwsHTTPHeaderTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    JwsWriterInterceptor jwsWriterInterceptor = new JwsWriterInterceptor();
    jwsWriterInterceptor.setProtectHttpHeaders(true);
    providers.add(jwsWriterInterceptor);
    String address = "http://localhost:" + PORT + "/jwsheadercustom/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/jwkPrivateSet.txt");
    properties.put("rs.security.signature.algorithm", "RS256");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    WebClient.getConfig(client).getOutInterceptors().add(new CustomHeaderInterceptor(Phase.PRE_STREAM));
    // Expect failure on not signing all of the required headers
    Response response = client.post(new Book("book", 123L));
    assertNotEquals(response.getStatus(), 200);
    Set<String> headersToSign = new HashSet<>();
    headersToSign.add(HttpHeaders.CONTENT_TYPE);
    headersToSign.add(HttpHeaders.ACCEPT);
    headersToSign.add("customheader");
    jwsWriterInterceptor.setProtectedHttpHeaders(headersToSign);
    response = client.post(new Book("book", 123L));
    response = client.post(new Book("book", 123L));
    assertEquals(response.getStatus(), 200);
}
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) Book(org.apache.cxf.systest.jaxrs.security.Book) JwsWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor) HashSet(java.util.HashSet)

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