Skip to content

Commit

Permalink
Fix SCIM URI schema fields
Browse files Browse the repository at this point in the history
  • Loading branch information
luca committed Jun 18, 2024
1 parent d997a6b commit eead5c3
Showing 1 changed file with 42 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,6 @@ private void applyAddWithValueFilter(
private void applyAdd(final ObjectNode node) throws ScimException
{
Path path = null;
List<Path> existingPaths = Collections.emptyList();
List<Path> nonExistingPaths = Collections.emptyList();
if (getPath() == null)
{
if (value.getNodeType() == JsonNodeType.OBJECT)
Expand All @@ -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<Path> 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
{
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit eead5c3

Please sign in to comment.