bdemers commented on code in PR #454:
URL: https://github.com/apache/directory-scimple/pull/454#discussion_r1428713069
##########
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:
This is a bit ugly, but I assume we want to fail if we detect a different
version of this non-spec request.
Open to thoughts on cleaning this up!
--
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]