Class JwtHeaderInjecter

java.lang.Object
com.ibm.websphere.security.jwt.JwtHeaderInjecter
All Implemented Interfaces:
jakarta.ws.rs.client.ClientRequestFilter

public class JwtHeaderInjecter extends Object implements jakarta.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.

Sample code to propagate the JWT Token
        // 1. Create a jax-rs client
         jakarta.ws.rs.client.Client client = jakarta.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)


 
Since:
1.1
  • Constructor Summary

    Constructors
    Constructor
    Description
    Retrieves the JWT token from the Subject on the thread.
    Retrieves the JWT token from the Subject on the thread.
    JwtHeaderInjecter(String headername, String builder)
    Self issues a JWT token using the specified JWT builder configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    filter(jakarta.ws.rs.client.ClientRequestContext requestContext)
    Adds the JWT token to the Authorization header in the jax-rs client requests to propagate the token.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JwtHeaderInjecter

      public JwtHeaderInjecter() throws Exception
      Retrieves the JWT token from the Subject on the thread. The filter will add the JWT token to the Authorization header using the default header "Authorization".
      Throws:
      Exception
    • JwtHeaderInjecter

      public JwtHeaderInjecter(String headername) throws Exception
      Retrieves the JWT token from the Subject on the thread. The filter will add the JWT token to the header using the specified header name.
      Parameters:
      headername - custom header name to use.
      Throws:
      Exception
    • JwtHeaderInjecter

      public JwtHeaderInjecter(String headername, String builder) throws Exception
      Self issues a JWT token using the specified JWT builder configuration. The filter will add the JWT token to the header using the specified header name.
      Parameters:
      headername - custom header name to use.
      builder - ID of a corresponding jwtBuilder element in the server configuration.
      Throws:
      Exception
  • Method Details

    • filter

      public void filter(jakarta.ws.rs.client.ClientRequestContext requestContext)
      Adds the JWT token to the Authorization header in the jax-rs client requests to propagate the token.
      Specified by:
      filter in interface jakarta.ws.rs.client.ClientRequestFilter
      Parameters:
      requestContext - jax-rs client request context