public class JwtHeaderInjecter
extends java.lang.Object
implements javax.ws.rs.client.ClientRequestFilter
These jax-rs client request filter APIs retrieve the JWT token from the
subject on the thread or self issue a JWT token and then adds the token to
the jax-rs client request header to propagate the JWT token.
The code snippet that is shown here demonstrate how to use these APIs to
propagate the token.
// 1. Create a jax-rs client
javax.ws.rs.client.Client client = javax.ws.rs.client.ClientBuilder.newClient();
// 2. Register the jwt client request filter api using one of the three ways shown here
client.register(new JwtHeaderInjecter()); or
client.register(new JwtHeaderInjecter("customHeader")); or
client.register(new JwtHeaderInjecter("customHeader","jwtBuilder"));
// 3. Make REST request - The jwt token from the subject on the thread will be added to the default header "Authorization" or to the custom header
String response = client.target(requesturl).request("text/plain").get(String.class)
| Constructor and Description |
|---|
JwtHeaderInjecter()
Retrieves the JWT token from the Subject on the thread.
|
JwtHeaderInjecter(java.lang.String headername)
Retrieves the JWT token from the Subject on the thread.
|
JwtHeaderInjecter(java.lang.String headername,
java.lang.String builder)
Self issues a JWT token using the specified JWT builder configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
filter(javax.ws.rs.client.ClientRequestContext requestContext)
Adds the JWT token to the Authorization header in the jax-rs client
requests to propagate the token.
|
public JwtHeaderInjecter()
throws java.lang.Exception
java.lang.Exceptionpublic JwtHeaderInjecter(java.lang.String headername)
throws java.lang.Exception
headername - custom header name to use.java.lang.Exceptionpublic JwtHeaderInjecter(java.lang.String headername,
java.lang.String builder)
throws java.lang.Exception
headername - custom header name to use.builder - ID of a corresponding jwtBuilder element in the server
configuration.java.lang.Exceptionpublic void filter(javax.ws.rs.client.ClientRequestContext requestContext)
filter in interface javax.ws.rs.client.ClientRequestFilterrequestContext - jax-rs client request context