Java Code Examples for com.fasterxml.jackson.databind.JsonNode#iterator()

The following examples show how to use com.fasterxml.jackson.databind.JsonNode#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseSpringRestTestCase.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the returned "data" array (child-node of root-json node returned by invoking a GET on the given url) contains entries with the given ID's.
 */
protected void assertResultsPresentInDataResponse(String url, String... expectedResourceIds) throws JsonProcessingException, IOException {
  int numberOfResultsExpected = expectedResourceIds.length;

  // Do the actual call
  CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

  // Check status and size
  JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
  closeResponse(response);
  assertEquals(numberOfResultsExpected, dataNode.size());

  // Check presence of ID's
  List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
  Iterator<JsonNode> it = dataNode.iterator();
  while (it.hasNext()) {
    String id = it.next().get("id").textValue();
    toBeFound.remove(id);
  }
  assertTrue("Not all expected ids have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
}
 
Example 2
Source File: IntegerSampler.java    From log-synth with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the distribution to be used. The format is a list of number pairs.
 * The first value in each pair is the value to return, the second is the
 * (unnormalized) probability for that number. For instance [1, 50, 2, 30, 3, 1]
 * will cause the sampler to return 1 a bit less than 60% of the time, 2 a bit
 * less than 40% of the time and 3 just a bit over 1% of the time.
 *
 * @param dist A JSON list describing the distribution of numbers.
 */
public void setDist(JsonNode dist) {
    if (dist.isArray()) {
        if (dist.size() % 2 != 0) {
            throw new IllegalArgumentException("Need distribution to be an even sized list of numbers");
        }
        this.dist = new Multinomial<>();
        Iterator<JsonNode> i = dist.iterator();
        while (i.hasNext()) {
            JsonNode v = i.next();
            JsonNode p = i.next();
            if (!v.canConvertToLong() || !p.isNumber()) {
                throw new IllegalArgumentException(String.format("Need distribution to be a list of value, probability pairs, got %s (%s,%s)", dist, v.getClass(), p.getClass()));
            }
            this.dist.add(v.asLong(), p.asDouble());
        }
    }
}
 
Example 3
Source File: BaseSpringRestTestCase.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the returned "data" array (child-node of root-json node returned by invoking a GET on the given url) contains entries with the given ID's.
 */
protected void assertResultsPresentInDataResponse(String url, String... expectedResourceIds) throws JsonProcessingException, IOException {
    int numberOfResultsExpected = expectedResourceIds.length;

    // Do the actual call
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);
    assertThat(dataNode).hasSize(numberOfResultsExpected);

    // Check presence of ID's
    List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedResourceIds));
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        String id = it.next().get("id").textValue();
        toBeFound.remove(id);
    }
    assertThat(toBeFound.isEmpty()).as("Not all expected ids have been found in result, missing: " + StringUtils.join(toBeFound, ", ")).isTrue();
}
 
Example 4
Source File: JSONUtil.java    From strimzi-kafka-oauth with Apache License 2.0 6 votes vote down vote up
public static List<String> asListOfString(JsonNode arrayNode) {

        ArrayList<String> result = new ArrayList<>();

        if (arrayNode.isTextual()) {
            result.addAll(Arrays.asList(arrayNode.asText().split(" ")));
        } else {
            if (!arrayNode.isArray()) {
                throw new IllegalArgumentException("JsonNode not a text node, nor an array node: " + arrayNode);
            }

            Iterator<JsonNode> it = arrayNode.iterator();
            while (it.hasNext()) {
                JsonNode n = it.next();
                if (n.isTextual()) {
                    result.add(n.asText());
                } else {
                    result.add(n.toString());
                }
            }
        }

        return result;
    }
 
Example 5
Source File: LinkedInIdentityProvider.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private String getFirstMultiLocaleString(JsonNode node, String name) {
	JsonNode claim = node.get(name);

	if (claim != null) {
		JsonNode localized = claim.get("localized");

		if (localized != null) {
			Iterator<JsonNode> iterator = localized.iterator();

			if (iterator.hasNext()) {
				return iterator.next().asText();
			}
		}
	}

	return null;
}
 
Example 6
Source File: BaseSpringDmnRestTestCase.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the returned "data" array (child-node of root-json node returned by invoking a GET on the given url) contains entries with the given ID's.
 */
protected void assertResultsPresentInDataResponse(String url, String... expectedResourceIds) throws JsonProcessingException, IOException {
  int numberOfResultsExpected = expectedResourceIds.length;

  // Do the actual call
  CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

  // Check status and size
  JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
  closeResponse(response);
  assertEquals(numberOfResultsExpected, dataNode.size());

  // Check presence of ID's
  List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
  Iterator<JsonNode> it = dataNode.iterator();
  while (it.hasNext()) {
    String id = it.next().get("id").textValue();
    toBeFound.remove(id);
  }
  assertTrue("Not all expected ids have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
}
 
Example 7
Source File: OperatorDeserializer.java    From yare with MIT License 5 votes vote down vote up
private List<Operand> mapNodeAsListOfOperands(JsonNode jsonNode, ObjectMapper objectMapper) throws JsonProcessingException {
    Iterator<JsonNode> operandNodes = jsonNode.iterator();
    List<Operand> operands = new ArrayList<>();
    while (operandNodes.hasNext()) {
        JsonNode node = operandNodes.next();
        Operand o = objectMapper.treeToValue(node, Operand.class);
        operands.add(o);
    }
    return operands;
}
 
Example 8
Source File: BaseSpringRestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
  int numberOfResultsExpected = 0;
  if (expectedResourceIds != null) {
    numberOfResultsExpected = expectedResourceIds.length;
  }

  // Do the actual call
  HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
  post.setEntity(new StringEntity(body.toString()));
  CloseableHttpResponse response = executeRequest(post, expectedStatusCode);

  if (expectedStatusCode == HttpStatus.SC_OK) {
    // Check status and size
    JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
    JsonNode dataNode = rootNode.get("data");
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedResourceIds != null) {
      List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
      Iterator<JsonNode> it = dataNode.iterator();
      while (it.hasNext()) {
        String id = it.next().get("id").textValue();
        toBeFound.remove(id);
      }
      assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
    }
  }

  closeResponse(response);
}
 
Example 9
Source File: BaseSpringRestTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
    int numberOfResultsExpected = 0;
    if (expectedResourceIds != null) {
        numberOfResultsExpected = expectedResourceIds.length;
    }

    // Do the actual call
    HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
    post.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(post, expectedStatusCode);

    if (expectedStatusCode == HttpStatus.SC_OK) {
        // Check status and size
        JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
        JsonNode dataNode = rootNode.get("data");
        assertThat(dataNode).hasSize(numberOfResultsExpected);

        // Check presence of ID's
        if (expectedResourceIds != null) {
            List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedResourceIds));
            Iterator<JsonNode> it = dataNode.iterator();
            while (it.hasNext()) {
                String id = it.next().get("id").textValue();
                toBeFound.remove(id);
            }
            assertThat(toBeFound).as("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", ")).isEmpty();
        }
    }

    closeResponse(response);
}
 
Example 10
Source File: CommaSeparatedToMultivaluedMetadata.java    From storm-crawler with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Map stormConf, JsonNode filterParams) {
    JsonNode node = filterParams.get("keys");
    if (node == null) {
        return;
    }
    if (node.isArray()) {
        Iterator<JsonNode> iter = node.iterator();
        while (iter.hasNext()) {
            keys.add(iter.next().asText());
        }
    } else {
        keys.add(node.asText());
    }
}
 
Example 11
Source File: BaseJPARestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
  int numberOfResultsExpected = 0;
  if (expectedResourceIds != null) {
    numberOfResultsExpected = expectedResourceIds.length;
  }

  // Do the actual call
  HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
  post.setEntity(new StringEntity(body.toString()));
  HttpResponse response = executeHttpRequest(post, expectedStatusCode);

  if (expectedStatusCode == HttpStatus.SC_OK) {
    // Check status and size
    JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
    JsonNode dataNode = rootNode.get("data");
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedResourceIds != null) {
      List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
      Iterator<JsonNode> it = dataNode.iterator();
      while (it.hasNext()) {
        String id = it.next().get("id").textValue();
        toBeFound.remove(id);
      }
      assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
    }
  }
}
 
Example 12
Source File: HistoricDetailQueryResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void assertResultsPresentInDataResponse(String url, ObjectNode body, int numberOfResultsExpected, String variableName, Object variableValue) throws JsonProcessingException, IOException {

    // Do the actual call
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
    httpPost.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, 200);

    // Check status and size
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (variableName != null) {
      boolean variableFound = false;
      Iterator<JsonNode> it = dataNode.iterator();
      while (it.hasNext()) {
        JsonNode variableNode = it.next().get("variable");
        String name = variableNode.get("name").textValue();
        if (variableName.equals(name)) {
          variableFound = true;
          if (variableValue instanceof Boolean) {
            assertTrue("Variable value is not equal", variableNode.get("value").asBoolean() == (Boolean) variableValue);
          } else if (variableValue instanceof Integer) {
            assertTrue("Variable value is not equal", variableNode.get("value").asInt() == (Integer) variableValue);
          } else {
            assertTrue("Variable value is not equal", variableNode.get("value").asText().equals((String) variableValue));
          }
        }
      }
      assertTrue("Variable " + variableName + " is missing", variableFound);
    }
  }
 
Example 13
Source File: BaseSpringDmnRestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
  int numberOfResultsExpected = 0;
  if (expectedResourceIds != null) {
    numberOfResultsExpected = expectedResourceIds.length;
  }

  // Do the actual call
  HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
  post.setEntity(new StringEntity(body.toString()));
  CloseableHttpResponse response = executeRequest(post, expectedStatusCode);

  if (expectedStatusCode == HttpStatus.SC_OK) {
    // Check status and size
    JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
    JsonNode dataNode = rootNode.get("data");
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedResourceIds != null) {
      List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
      Iterator<JsonNode> it = dataNode.iterator();
      while (it.hasNext()) {
        String id = it.next().get("id").textValue();
        toBeFound.remove(id);
      }
      assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
    }
  }

  closeResponse(response);
}
 
Example 14
Source File: ValuesDeserializer.java    From yare with MIT License 5 votes vote down vote up
private List<Expression> mapNodeAsListOfExpressions(JsonNode jsonNode, ObjectMapper objectMapper) throws JsonProcessingException {
    Iterator<JsonNode> valueNodes = jsonNode.iterator();
    List<Expression> expressions = new ArrayList<>();
    while (valueNodes.hasNext()) {
        JsonNode node = valueNodes.next();
        Expression e = objectMapper.treeToValue(node, Expression.class);
        expressions.add(e);
    }
    return expressions;
}
 
Example 15
Source File: BaseSpringRestTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
    int numberOfResultsExpected = 0;
    if (expectedResourceIds != null) {
        numberOfResultsExpected = expectedResourceIds.length;
    }

    // Do the actual call
    HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
    post.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(post, expectedStatusCode);

    if (expectedStatusCode == HttpStatus.SC_OK) {
        // Check status and size
        JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
        JsonNode dataNode = rootNode.get("data");
        assertThat(dataNode).hasSize(numberOfResultsExpected);

        // Check presence of ID's
        if (expectedResourceIds != null) {
            List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedResourceIds));
            Iterator<JsonNode> it = dataNode.iterator();
            while (it.hasNext()) {
                String id = it.next().get("id").textValue();
                toBeFound.remove(id);
            }
            assertThat(toBeFound).as("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", ")).isEmpty();
        }
    }

    closeResponse(response);
}
 
Example 16
Source File: BaseSpringDmnRestTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
    int numberOfResultsExpected = 0;
    if (expectedResourceIds != null) {
        numberOfResultsExpected = expectedResourceIds.length;
    }

    // Do the actual call
    HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
    post.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(post, expectedStatusCode);

    if (expectedStatusCode == HttpStatus.SC_OK) {
        // Check status and size
        JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
        JsonNode dataNode = rootNode.get("data");
        assertEquals(numberOfResultsExpected, dataNode.size());

        // Check presence of ID's
        if (expectedResourceIds != null) {
            List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedResourceIds));
            Iterator<JsonNode> it = dataNode.iterator();
            while (it.hasNext()) {
                String id = it.next().get("id").textValue();
                toBeFound.remove(id);
            }
            assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
        }
    }

    closeResponse(response);
}
 
Example 17
Source File: JsonUtilities.java    From constellation with Apache License 2.0 5 votes vote down vote up
public static Iterator<Integer> getIntegerFieldIterator(JsonNode node, String... keys) {
    JsonNode current = node;
    for (final String key : keys) {
        if (!current.hasNonNull(key)) {
            return new Iterator<Integer>() {
                @Override
                public boolean hasNext() {
                    return false;
                }

                @Override
                public Integer next() {
                    throw new NoSuchElementException();
                }
            };
        }
        current = current.get(key);
    }
    Iterator<JsonNode> nodeIter = current.iterator();
    return new Iterator<Integer>() {
        @Override
        public boolean hasNext() {
            return nodeIter.hasNext();
        }

        @Override
        public Integer next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            return nodeIter.next().intValue();
        }
    };
}
 
Example 18
Source File: JsonUtilities.java    From constellation with Apache License 2.0 5 votes vote down vote up
public static Iterator<String> getTextFieldIterator(JsonNode node, String... keys) {
    JsonNode current = node;
    for (final String key : keys) {
        if (!current.hasNonNull(key)) {
            return new Iterator<String>() {
                @Override
                public boolean hasNext() {
                    return false;
                }

                @Override
                public String next() {
                    throw new NoSuchElementException();
                }
            };
        }
        current = current.get(key);
    }
    Iterator<JsonNode> nodeIter = current.iterator();
    return new Iterator<String>() {
        @Override
        public boolean hasNext() {
            return nodeIter.hasNext();
        }

        @Override
        public String next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            return nodeIter.next().textValue();
        }
    };
}
 
Example 19
Source File: HistoricDetailQueryResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test querying historic detail. POST query/historic-detail
 */
@Test
@Deployment
public void testQueryDetail() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    processVariables.put("byteVar", "test".getBytes());

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "test");

    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);

    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_DETAIL_QUERY);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance.getId());
    assertResultsPresentInDataResponse(url, requestNode, 5, "stringVar", "Azerty");

    requestNode = objectMapper.createObjectNode();
    requestNode.put("taskId", task.getId());
    assertResultsPresentInDataResponse(url, requestNode, 1, "taskVariable", "test");

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    assertResultsPresentInDataResponse(url, requestNode, 4, "intVar", 67890);

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    requestNode.put("selectOnlyFormProperties", true);
    assertResultsPresentInDataResponse(url, requestNode, 0, null, null);

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    requestNode.put("selectOnlyVariableUpdates", true);
    assertResultsPresentInDataResponse(url, requestNode, 4, "booleanVar", false);

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, 200);

    // Check status and size
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK);
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);

    boolean byteVarFound = false;
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        JsonNode variableNode = it.next().get("variable");
        String name = variableNode.get("name").textValue();
        if ("byteVar".equals(name)) {
            byteVarFound = true;
            String valueUrl = variableNode.get("valueUrl").textValue();
            response = executeRequest(new HttpGet(valueUrl), 200);
            assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK);
            byte[] varInput = IOUtils.toByteArray(response.getEntity().getContent());
            closeResponse(response);
            assertThat(new String(varInput)).isEqualTo("test");
            break;
        }
    }
    assertThat(byteVarFound).isTrue();
}
 
Example 20
Source File: KeycloakIdentity.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public KeycloakIdentity(AccessToken accessToken, KeycloakSession keycloakSession) {
    if (accessToken == null) {
        throw new ErrorResponseException("invalid_bearer_token", "Could not obtain bearer access_token from request.", Status.FORBIDDEN);
    }
    if (keycloakSession == null) {
        throw new ErrorResponseException("no_keycloak_session", "No keycloak session", Status.FORBIDDEN);
    }
    this.accessToken = accessToken;
    this.keycloakSession = keycloakSession;
    this.realm = keycloakSession.getContext().getRealm();

    Map<String, Collection<String>> attributes = new HashMap<>();

    try {
        ObjectNode objectNode = JsonSerialization.createObjectNode(this.accessToken);
        Iterator<String> iterator = objectNode.fieldNames();

        while (iterator.hasNext()) {
            String fieldName = iterator.next();
            JsonNode fieldValue = objectNode.get(fieldName);
            List<String> values = new ArrayList<>();

            if (fieldValue.isArray()) {
                Iterator<JsonNode> valueIterator = fieldValue.iterator();

                while (valueIterator.hasNext()) {
                    values.add(valueIterator.next().asText());
                }
            } else {
                String value = fieldValue.asText();

                if (StringUtil.isNullOrEmpty(value)) {
                    continue;
                }

                values.add(value);
            }

            if (!values.isEmpty()) {
                attributes.put(fieldName, values);
            }
        }

        AccessToken.Access realmAccess = accessToken.getRealmAccess();

        if (realmAccess != null) {
            attributes.put("kc.realm.roles", realmAccess.getRoles());
        }

        Map<String, AccessToken.Access> resourceAccess = accessToken.getResourceAccess();

        if (resourceAccess != null) {
            resourceAccess.forEach((clientId, access) -> attributes.put("kc.client." + clientId + ".roles", access.getRoles()));
        }

        ClientModel clientModel = getTargetClient();
        UserModel clientUser = null;

        if (clientModel != null) {
            clientUser = this.keycloakSession.users().getServiceAccount(clientModel);
        }

        UserModel userSession = getUserFromSessionState();

        this.resourceServer = clientUser != null && userSession.getId().equals(clientUser.getId());

        if (resourceServer) {
            this.id = clientModel.getId();
        } else {
            this.id = userSession.getId();
        }
    } catch (Exception e) {
        throw new RuntimeException("Error while reading attributes from security token.", e);
    }

    this.attributes = Attributes.from(attributes);
}