Class JwtConsumer

java.lang.Object
com.ibm.websphere.security.jwt.JwtConsumer

public class JwtConsumer extends Object
This is a class that facilitates validating and parsing JSON Web Tokens.
Since:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The ID used for the default jwtConsumer server configuration element that it implicitly included with the jwt-1.0 feature.
  • Constructor Summary

    Constructors
    Constructor
    Description
    End OSGi-related fields and methods
    JwtConsumer(String consumerConfigId)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new JwtConsumer object using the default configuration ID "defaultJwtConsumer".
    create(String consumerConfigId)
    Creates a new JwtConsumer object using the configuration ID provided.
    createJwt(String encodedTokenString)
    Creates a new JwtToken object based on the provided encoded token string.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_ID

      public static final String DEFAULT_ID
      The ID used for the default jwtConsumer server configuration element that it implicitly included with the jwt-1.0 feature.
      See Also:
  • Constructor Details

  • Method Details

    • create

      public static JwtConsumer create() throws InvalidConsumerException
      Creates a new JwtConsumer object using the default configuration ID "defaultJwtConsumer".
      Returns:
      A new JwtConsumer object tied to the jwtConsumer server configuration element with the default ID "defaultJwtConsumer".
      Throws:
      InvalidConsumerException - Thrown if the JWT consumer service is not available.
    • create

      public static JwtConsumer create(String consumerConfigId) throws InvalidConsumerException
      Creates a new JwtConsumer object using the configuration ID provided.
      Parameters:
      consumerConfigId - ID of a corresponding jwtConsumer element in server.xml. If null, the default configuration ID "defaultJwtConsumer" will be used.
      Returns:
      A new JwtConsumer object tied to the jwtConsumer server configuration element whose id attribute matches the ID provided.
      Throws:
      InvalidConsumerException - Thrown if the JWT consumer service is not available.
    • createJwt

      public JwtToken createJwt(String encodedTokenString) throws InvalidTokenException, InvalidConsumerException
      Creates a new JwtToken object based on the provided encoded token string. The token string is processed based on the configuration for the jwtConsumer element that is specified in server.xml that matches the ID used to instantiate this JwtConsumer object.
      Parameters:
      encodedTokenString - JWT string to be used to create and validate a new JwtToken object. The string should adhere to the format described in {@link https://tools.ietf.org/html/rfc7519#section-3}, where the string is a sequence of base64url-encoded URL-safe parts separated by period ('.') characters.
      Returns:
      A new JwtToken object based on the data contained in the provided token string.
      Throws:
      InvalidConsumerException - Thrown if a jwtConsumer element with the ID used to instantiate this JwtConsumer object cannot be found in the server configuration.
      InvalidTokenException - Thrown if the provided token string is null or empty, or if there is an error while processing the token string.