Class JsonPathQuery

java.lang.Object
io.strimzi.kafka.oauth.jsonpath.JsonPathQuery

public class JsonPathQuery extends Object
This class implements the support for JSONPath querying as implemented by: https://github.com/json-path/JsonPath Given the following content of the JWT token:
   {
     "aud": ["uma_authorization", "kafka"],
     "iss": "https://auth-server/sso",
     "iat": 0,
     "exp": 600,
     "sub": "username",
     "custom": "custom-value",
     "roles": {
       "client-roles": {
         "kafka": ["kafka-user"]
       }
     },
     "custom-level": 9
   }
 
Some examples of valid queries are:
   $.custom
   $['aud']
   $.roles.client-roles.kafka
   $['roles']['client-roles']['kafka']
 
See Jayway JsonPath project for full syntax.

This class takes a JSONPath expression and applies it as-is.

The JWT token is used in its original payload form, for example:

   {
      "sub": "username",
      "iss": "https://auth-server/sso",
      "custom": "custom value",
      ...
   }
 
Usage:
   JsonPathQuery query = new JsonPathQuery("$.roles");
   JsonNode result = query.apply(jsonObject);
 
Query is parsed in the first line and any error during parsing results in JsonPathQueryException. Matching is thread safe. The normal usage pattern is to initialise the JsonPathFilterQuery object once, and query it many times concurrently against json objects. In addition to filtering this helper can also be used to apply JsonPath query to extract a result containing the matching keys.
  • Method Details

    • parse

      public static JsonPathQuery parse(String query)
      Construct a new JsonPathQuery
      Parameters:
      query - The query using the JSONPath syntax
      Returns:
      New JsonPathQuery instance
    • apply

      public com.fasterxml.jackson.databind.JsonNode apply(com.fasterxml.jackson.databind.JsonNode jsonObject)
      Apply the JsonPath query to passed object
      Parameters:
      jsonObject - Jackson DataBind object
      Returns:
      The Jackson JsonNode object with the result
    • toString

      public String toString()
      Overrides:
      toString in class Object