From eead5c30b1a2061e47910e6f156ad98970830ec0 Mon Sep 17 00:00:00 2001 From: luca Date: Tue, 18 Jun 2024 17:23:08 +0200 Subject: [PATCH] Fix SCIM URI schema fields --- .../scim2/common/messages/PatchOperation.java | 108 +++++++----------- 1 file changed, 42 insertions(+), 66 deletions(-) diff --git a/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/PatchOperation.java b/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/PatchOperation.java index 632705e1..8dd6c29e 100644 --- a/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/PatchOperation.java +++ b/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/PatchOperation.java @@ -420,8 +420,6 @@ private void applyAddWithValueFilter( private void applyAdd(final ObjectNode node) throws ScimException { Path path = null; - List existingPaths = Collections.emptyList(); - List nonExistingPaths = Collections.emptyList(); if (getPath() == null) { if (value.getNodeType() == JsonNodeType.OBJECT) @@ -443,76 +441,43 @@ private void applyAdd(final ObjectNode node) throws ScimException if (containsDot) { - existingPaths = keys.stream().filter(key -> - { - try - { - return JsonUtils.pathExists(Path.fromString(key), node); - } - catch (final BadRequestException e) - { - return false; - } - catch (final ScimException e) - { - return false; - } - }).map(key -> + final ObjectNode removedValues = (ObjectNode) value.deepCopy(); + final List dotPaths = keys.stream().filter(key -> key.contains(".")) + .map(key -> { + try + { + return Path.fromString(key); + } + catch (final BadRequestException e) + { + return Path.root(); + } + }).collect(Collectors.toList()); + + for (final Path dotPath : dotPaths) { - try - { - return Path.fromString(key); - } - catch (final BadRequestException e) + JsonNode dotPathJsonNode = value.get(dotPath.toString()); + if (SchemaUtils.isUrn(dotPath.toString())) { - return Path.root(); - } - }).collect(Collectors.toList()); + if (dotPathJsonNode.getNodeType() != JsonNodeType.OBJECT && + dotPathJsonNode.getNodeType() != JsonNodeType.ARRAY) + { + JsonUtils.addValue(dotPath, node, dotPathJsonNode); - nonExistingPaths = keys.stream().filter(key -> - { - try - { - return !JsonUtils.pathExists(Path.fromString(key), node); + removedValues.remove(dotPath.toString()); + } } - catch (final BadRequestException e) - { - return false; - } - catch (final ScimException e) - { - return false; - } - }).map(key -> - { - try - { - return Path.fromString(key); - } - catch (final BadRequestException e) + else { - return Path.root(); - } - }).collect(Collectors.toList()); - - for (final Path existingPath : existingPaths) - { - JsonUtils.addValue(existingPath, node, value.get(existingPath.toString())); - } - for (final Path nonExistingPath : nonExistingPaths) - { - if (nonExistingPath.toString().contains(":")) - { - path = Path.root(); + JsonUtils.addValue(dotPath, node, dotPathJsonNode); - JsonUtils.addValue(path, node, value); - } - else - { - JsonUtils.addValue(nonExistingPath, node, value.get(nonExistingPath.toString())); + removedValues.remove(dotPath.toString()); } } + + path = Path.root(); + JsonUtils.addValue(path, node, removedValues); } else { @@ -1096,15 +1061,26 @@ else if(getPath().getSchemaUrn() != null) private void addSchemaUrnIfMissing(@NotNull final ArrayNode schemas, @NotNull final String schemaUrn) { - for(JsonNode node : schemas) + final String enterpriseUserUri = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"; + for (final JsonNode node : schemas) { - if(node.isTextual() && node.textValue().equalsIgnoreCase(schemaUrn)) + if (node.isTextual() + && (node.textValue().equalsIgnoreCase(schemaUrn) + || node.textValue().toUpperCase().contains(enterpriseUserUri.toUpperCase()))) { return; } } - schemas.add(schemaUrn); + if (schemaUrn.toUpperCase().contains(enterpriseUserUri.toUpperCase()) + && schemaUrn.length() > enterpriseUserUri.length()) + { + schemas.add(enterpriseUserUri); + } + else + { + schemas.add(schemaUrn); + } } /**