...
JwsClientResponseFilter and JwsContainerRequestFilter process the incoming client or server Compact JWS sequences.
Here is an example of a JSON Book representation being signed and converted into Compact JWS and POSTed to the target service:
No Format |
---|
Address: https://localhost:9001/jwsjwkhmac/bookstore/books
Http-Method: POST
Content-Type: application/jose
Payload:
eyJhbGciOiJIUzI1NiIsImN0eSI6Impzb24ifQ.
eyJCb29rIjp7ImlkIjoxMjMsIm5hbWUiOiJib29rIn19.
hg1T41ESuX6JvRR--huTA3HnbrsdIZSwkxQdyWj9j6c |
You can see 3 JWS parts (put on separate lines for the better readibility) separated by dots. The 1st part is Base64Url encoded protected headers, next one - Base64Url encoded Book JSON payload, finally - the signature.
The following client code can be used to set the client JOSE interceptors:
Code Block | ||||
---|---|---|---|---|
| ||||
@Test
public void testJwsJwkBookHMac() throws Exception {
String address = "https://localhost:" + PORT + "/jwsjwkhmac";
BookStore bs = createJwsBookStore(address);
Book book = bs.echoBook(new Book("book", 123L));
assertEquals("book", book.getName());
assertEquals(123L, book.getId());
}
private BookStore createJwsBookStore(String address,
List<?> mbProviders) throws Exception {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setServiceClass(BookStore.class);
bean.setAddress(address);
List<Object> providers = new LinkedList<Object>();
JwsWriterInterceptor jwsWriter = new JwsWriterInterceptor();
jwsWriter.setUseJwsOutputStream(true);
providers.add(jwsWriter);
providers.add(new JwsClientResponseFilter());
providers.add(new JacksonJsonProvider());
bean.getProperties(true).put("jose.debug", true);
bean.setProviders(providers);
bean.getProperties(true).put("rs.security.signature.properties",
"org/apache/cxf/systest/jaxrs/security/secret.jwk.properties");
return bean.create(BookStore.class);
} |
The above code shows a client proxy code but WebClient can be created instead with a bean.createWebClient() instead.
JwsJsonWriterInterceptor creates JWS JSON sequences on the client or server out directions.
...