kjthorpe18 commented on code in PR #454:
URL: https://github.com/apache/directory-scimple/pull/454#discussion_r1428820778
##########
scim-core/src/main/java/org/apache/directory/scim/core/repository/DefaultPatchHandler.java:
##########
@@ -426,5 +447,48 @@ public <T extends ScimResource> void applyMultiValue(T
source, Map<String, Objec
}
}
}
+
+ /**
+ * Detects Azure Quirk mode.
+ * Azure uses an out of spec patch operation that does not use an express,
Review Comment:
```suggestion
* Azure uses an out of spec patch operation that does not use a path
expression,
```
##########
scim-core/src/main/java/org/apache/directory/scim/core/repository/DefaultPatchHandler.java:
##########
@@ -426,5 +447,48 @@ public <T extends ScimResource> void applyMultiValue(T
source, Map<String, Objec
}
}
}
+
+ /**
+ * Detects Azure Quirk mode.
+ * Azure uses an out of spec patch operation that does not use an express,
+ * but instead uses a remove with a value. Detect this and convert it to
an expression
+ * <pre><code>
+ * {
+ * "op":"remove",
+ * "path":"members",
+ * "value":[{
+ * "value":"<id>"
+ * }]
+ * }
+ * </code></pre>
+ * @param valuePathExpression The valuePathExpression to check if it has a
null attribute
+ * @return true, if Azure patch REMOVE detected.
+ */
+ private static boolean isAzureRemoveQuirk(Attribute attribute,
ValuePathExpression valuePathExpression, Object value) {
+ return attribute.isMultiValued()
+ && attribute.getAttribute(VALUE_ATTRIBUTE_NAME) != null
+ && valuePathExpression.getAttributeExpression() == null
+ && value instanceof Collection;
+ }
+
+ private static List<String> azureQuirkValuesToRemove(Collection<?>
listOfMaps, Attribute attribute) {
+ return listOfMaps.stream()
+ .map(item -> {
+ if (!(item instanceof Map)) {
+ throw new IllegalArgumentException("Azure Remove Patch request
quirk detected, but 'value' is not a list of maps");
+ }
+ return (Map<?,?>) item;
+ })
+ .map(item -> {
+ Attribute valueAttribute =
attribute.getAttribute(VALUE_ATTRIBUTE_NAME);
+ Object itemValue = item.get(valueAttribute.getName());
+ if (!(itemValue instanceof String)) {
+ throw new IllegalArgumentException("Azure Remove Patch request
quirk detected, but item 'value' is not a string");
+ }
+
+ return (String) itemValue;
+ })
+ .collect(toList());
Review Comment:
My mind doesn't immediately jump to using streams, so it took a little
longer to understand what's happening, but this is fine!
##########
scim-core/src/main/java/org/apache/directory/scim/core/repository/DefaultPatchHandler.java:
##########
@@ -426,5 +447,48 @@ public <T extends ScimResource> void applyMultiValue(T
source, Map<String, Objec
}
}
}
+
+ /**
+ * Detects Azure Quirk mode.
+ * Azure uses an out of spec patch operation that does not use an express,
+ * but instead uses a remove with a value. Detect this and convert it to
an expression
+ * <pre><code>
+ * {
+ * "op":"remove",
+ * "path":"members",
+ * "value":[{
+ * "value":"<id>"
+ * }]
Review Comment:
Note that this is how Azure structures the request, but in theory, it could
have other key:value pairs here, e.g.
```
"value":[{
"value":"<id>"
"display":"someDisplayName",
"ref":"https://scim-example.com/api/v2/Users/<id>",
}]
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]