Class JsonUtils

java.lang.Object
org.keycloak.utils.JsonUtils

public class JsonUtils extends Object
Utility methods for manipulating JSON objects.
  • Constructor Details

    • JsonUtils

      public JsonUtils()
  • Method Details

    • splitClaimPath

      public static List<String> splitClaimPath(String claim)
      Splits the given claim into separate paths if the value contains separators as per CLAIM_COMPONENT.
      Parameters:
      claim - the claim
      Returns:
      a list with the paths
    • mapClaim

      public static void mapClaim(List<String> split, Object attributeValue, Map<String,Object> jsonObject, boolean isMultivalued)
      Maps the Claim with the value attributeValue into the jsonObject under the path split.
      Input
      • split = ["user", "profile", "email"]
      • attributeValue = "alice@example.com"
      • isMultivalued = false
      • jsonObject = {"foo": "bar"}

      Output
       
       {
         "user": {
           "profile": {
             "email": "alice@example.com"
           }
         },
         "foo": "bar"
       }
       
       
      Parameters:
      split - The claim path (as created by splitClaimPath(String)) of the (sub-)claim to map into.
      attributeValue - the value to map into the claim.
      jsonObject - the object that contains the claims (e.g., the value that will be used as the claim container)
      isMultivalued - whether the claim should be treated as multivalued (i.e., multiple values for the same claim should be built into a JSON array).
    • hasPath

      public static boolean hasPath(String claim)
      Determines if the given claim contains paths.
      Parameters:
      claim - the claim
      Returns:
      true if the claim contains paths. Otherwise, false.
    • getJsonValue

      public static Object getJsonValue(com.fasterxml.jackson.databind.JsonNode node, String claim)

      Returns the value corresponding to the given claim.

      Parameters:
      node - the JSON node
      claim - the claim
      Returns:
      the value
    • getJsonValue

      public static Object getJsonValue(com.fasterxml.jackson.databind.JsonNode node, List<String> paths)