Package io.strimzi.kafka.oauth.jsonpath
Class JsonPathQuery
java.lang.Object
io.strimzi.kafka.oauth.jsonpath.JsonPathQuery
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 Summary
-
Method Details
-
parse
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
-