Search in sources :

Example 66 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class BookStoreCustomApplication method getSingletons.

@Override
public Set<Object> getSingletons() {
    Set<Object> singletons = new HashSet<>();
    singletons.add(new JacksonJsonProvider());
    singletons.add(new ValidationExceptionMapper());
    singletons.add(new JAXRSBeanValidationFeature());
    singletons.add(new LoggingFilter());
    return singletons;
}
Also used : JAXRSBeanValidationFeature(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationFeature) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) LoggingFilter(org.apache.cxf.systests.cdi.base.bindings.LoggingFilter) ValidationExceptionMapper(org.apache.cxf.jaxrs.validation.ValidationExceptionMapper) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 67 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JweJwsAlgorithmTest method testEncryptionPBESDifferentCount.

@org.junit.Test
public void testEncryptionPBESDifferentCount() 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 + "/jwepbes/bookstore/books";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    Map<String, Object> properties = new HashMap<>();
    String password = "123456789123456789";
    properties.put("rs.security.encryption.content.algorithm", "A128GCM");
    properties.put("rs.security.encryption.key.algorithm", "PBES2-HS256+A128KW");
    properties.put("rs.security.key.password.provider", new PrivateKeyPasswordProviderImpl(password));
    properties.put("rs.security.encryption.pbes2.count", "1000");
    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 : 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) Book(org.apache.cxf.systest.jaxrs.security.Book)

Example 68 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JweJwsAlgorithmTest method testManualEncryption.

@org.junit.Test
public void testManualEncryption() throws Exception {
    URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    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);
    String header = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00iLCJjdHkiOiJqc29uIn0";
    String encryptedKey = "f_Njrwn8fLxvIfftV27lSqEgvyIvkfx5tcI6xJdzXqxSL-Xssaq9TFwbhiJIU6k23i1uLFDd3r7rL" + "V9THMcAo80C-m_SIbA6X4daeIm7ANmREZ9sw9QkD0URis6MAuZkoYIRB6z9g7TDmPTdrpTUWJbwYaBAe-_VYaoVBwRv_A" + "ikPdKJEUWSMxouJEq4TZUVveNjI_tflZpudz1mYXKv9Lw_5byYpwgIB9crI9BR0kfCK9x3BXVFMZHJAg0yIuAKDkcs9Ts" + "TIV0jLXRnb50Uc62OuJ6VFGQw-AL3tNHLRKYXjwDnE492wAZmsaxefql9wbv7b8BLmRUNeKER-26tdA";
    String iv = "rqUxWbEenVnC3QFx";
    String cipherText = "8iE2vM79BkXVJ0afH6fbig5uFpQ71nxc-i2SbokQtZO7";
    String authnTag = "bZk8RwVMZgawyFNSOkMLaw";
    // Successful test
    Response response = client.post(header + "." + encryptedKey + "." + iv + "." + cipherText + "." + authnTag);
    assertEquals(response.getStatus(), 200);
    // Tamper with the values
    response = client.post(header + "xyz." + encryptedKey + "." + iv + "." + cipherText + "." + authnTag);
    assertNotEquals(response.getStatus(), 200);
    response = client.post(header + "." + encryptedKey + "xyz." + iv + "." + cipherText + "." + authnTag);
    assertNotEquals(response.getStatus(), 200);
    response = client.post(header + "." + encryptedKey + "." + iv + "xyz." + cipherText + "." + authnTag);
    assertNotEquals(response.getStatus(), 200);
    response = client.post(header + "." + encryptedKey + "." + iv + "." + cipherText + "xyz." + authnTag);
    assertNotEquals(response.getStatus(), 200);
    response = client.post(header + "." + encryptedKey + "." + iv + "." + cipherText + "." + authnTag + "xyz");
    assertNotEquals(response.getStatus(), 200);
    response = client.post(header + "." + encryptedKey + "." + iv + "." + cipherText + ".");
    assertNotEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) 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 69 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JweJwsAlgorithmTest method testSignatureDynamic.

@org.junit.Test
public void testSignatureDynamic() 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", "RS256");
    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) 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 70 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JweJwsAlgorithmTest method testSignatureProperties.

// 
// Signature tests
// 
@org.junit.Test
public void testSignatureProperties() 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.signature.properties", "org/apache/cxf/systest/jaxrs/security/alice.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) 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)

Aggregations

JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)225 WebClient (org.apache.cxf.jaxrs.client.WebClient)152 Response (javax.ws.rs.core.Response)129 ArrayList (java.util.ArrayList)112 HashMap (java.util.HashMap)104 URL (java.net.URL)103 Book (org.apache.cxf.systest.jaxrs.security.Book)76 Test (org.junit.Test)66 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)50 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)50 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)45 List (java.util.List)31 ClientBuilder (javax.ws.rs.client.ClientBuilder)28 Number (org.apache.coheigea.cxf.jaxrs.json.common.Number)28 LinkedList (java.util.LinkedList)27 GenericType (javax.ws.rs.core.GenericType)27 JwsWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)27 MediaType (javax.ws.rs.core.MediaType)26 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)26 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)26