Search in sources :

Example 91 with Book

use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.

the class JWTPropertiesTest method testNearFutureTokenSuccess.

@org.junit.Test
public void testNearFutureTokenSuccess() throws Exception {
    URL busFile = JWTPropertiesTest.class.getResource("client.xml");
    List<Object> providers = new ArrayList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new JwtAuthenticationClientFilter());
    String address = "https://localhost:" + PORT + "/unsignedjwtnearfuture/bookstore/books";
    WebClient client = WebClient.create(address, providers, busFile.toString());
    client.type("application/json").accept("application/json");
    // Create the JWT Token
    JwtClaims claims = new JwtClaims();
    claims.setSubject("alice");
    claims.setIssuer("DoubleItSTSIssuer");
    claims.setAudiences(toList(address));
    // Set the issued date to be in the near future
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    claims.setIssuedAt(now.plusSeconds(30L).toEpochSecond());
    JwtToken token = new JwtToken(claims);
    Map<String, Object> properties = new HashMap<>();
    properties.put("rs.security.signature.algorithm", "none");
    properties.put(JwtConstants.JWT_TOKEN, token);
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    Response response = client.post(new Book("book", 123L));
    assertEquals(response.getStatus(), 200);
}
Also used : JwtClaims(org.apache.cxf.rs.security.jose.jwt.JwtClaims) 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) JwtToken(org.apache.cxf.rs.security.jose.jwt.JwtToken) Response(javax.ws.rs.core.Response) ZonedDateTime(java.time.ZonedDateTime) Book(org.apache.cxf.systest.jaxrs.security.Book) JwtAuthenticationClientFilter(org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)

Example 92 with Book

use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.

the class JAXRSJweJwsTest method testJweRsaJwsRsaXML.

// Test signing and encrypting an XML payload
@Test
public void testJweRsaJwsRsaXML() throws Exception {
    String address = "https://localhost:" + PORT + "/jwejwsrsa";
    BookStore bs = createJweJwsBookStore(address, null, null);
    Book book = new Book();
    book.setName("book");
    book = bs.echoBookXml(book);
    assertEquals("book", book.getName());
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.security.jose.BookStore) Book(org.apache.cxf.systest.jaxrs.security.Book) Test(org.junit.Test)

Example 93 with Book

use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.

the class JAXRSJweJwsTest method testJweJwkBookBeanRSA.

@Test
public void testJweJwkBookBeanRSA() throws Exception {
    String address = "https://localhost:" + PORT + "/jwejwkrsa";
    BookStore bs = createJweBookStore(address, Collections.singletonList(new JacksonJsonProvider()));
    Book book = bs.echoBook(new Book("book", 123L));
    assertEquals("book", book.getName());
    assertEquals(123L, book.getId());
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.security.jose.BookStore) Book(org.apache.cxf.systest.jaxrs.security.Book) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Test(org.junit.Test)

Example 94 with Book

use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.

the class JAXRSJwsMultipartTest method testJwsJwkBookHMacMultipartBuffered.

@Test
public void testJwsJwkBookHMacMultipartBuffered() throws Exception {
    String address = "https://localhost:" + PORT + "/jwsjwkhmac";
    BookStore bs = createJwsBookStoreHMac(address, true, false);
    Book book = bs.echoBookMultipart(new Book("book", 123L));
    assertEquals("book", book.getName());
    assertEquals(123L, book.getId());
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.security.jose.BookStore) Book(org.apache.cxf.systest.jaxrs.security.Book) Test(org.junit.Test)

Example 95 with Book

use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.

the class JAXRSJwsMultipartTest method testJwsJwkBookHMacMultipartModifiedBufferPayload.

@Test(expected = BadRequestException.class)
public void testJwsJwkBookHMacMultipartModifiedBufferPayload() throws Exception {
    String address = "https://localhost:" + PORT + "/jwsjwkhmacModifiedBufferPayload";
    BookStore bs = createJwsBookStoreHMac(address, true, false);
    bs.echoBookMultipartModified(new Book("book", 123L));
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.security.jose.BookStore) Book(org.apache.cxf.systest.jaxrs.security.Book) Test(org.junit.Test)

Aggregations

Book (org.apache.cxf.systest.jaxrs.security.Book)164 WebClient (org.apache.cxf.jaxrs.client.WebClient)144 URL (java.net.URL)121 Response (javax.ws.rs.core.Response)120 HashMap (java.util.HashMap)96 ArrayList (java.util.ArrayList)77 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)76 Test (org.junit.Test)74 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)41 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)39 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)35 KeyStore (java.security.KeyStore)30 PrivateKey (java.security.PrivateKey)30 MessageSigner (org.apache.cxf.rs.security.httpsignature.MessageSigner)30 CreateSignatureInterceptor (org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor)27 JwsWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)17 WebApplicationException (javax.ws.rs.WebApplicationException)15 JweWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor)15 BookStore (org.apache.cxf.systest.jaxrs.security.jose.BookStore)15 Bus (org.apache.cxf.Bus)13