diff --git a/src/Scim/SimpleIdServer.Scim/Extensions/JTokenExtensions.cs b/src/Scim/SimpleIdServer.Scim/Extensions/JTokenExtensions.cs new file mode 100644 index 000000000..6c392c34d --- /dev/null +++ b/src/Scim/SimpleIdServer.Scim/Extensions/JTokenExtensions.cs @@ -0,0 +1,11 @@ +// Copyright (c) SimpleIdServer. All rights reserved. +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. +using Newtonsoft.Json.Linq; + +namespace SimpleIdServer.Scim.Extensions; + +public static class JTokenExtensions +{ + public static bool IsEmpty(this JToken token) + => token == null || string.IsNullOrWhiteSpace(token.ToString()); +} diff --git a/src/Scim/SimpleIdServer.Scim/Helpers/RepresentationHelper.cs b/src/Scim/SimpleIdServer.Scim/Helpers/RepresentationHelper.cs index 1b0ed1343..35ed6e2b8 100644 --- a/src/Scim/SimpleIdServer.Scim/Helpers/RepresentationHelper.cs +++ b/src/Scim/SimpleIdServer.Scim/Helpers/RepresentationHelper.cs @@ -627,13 +627,12 @@ public static ICollection BuildRepresentationAttrib if (record.SchemaAttribute.MultiValued) { var jArr = record.Content as JArray; - if (jArr == null) + if (jArr == null && !record.Content.IsEmpty()) { throw new SCIMSchemaViolatedException(string.Format(Global.AttributeIsNotArray, record.SchemaAttribute.Name)); } - - attributes.AddRange(BuildAttributes(jArr, record.SchemaAttribute, record.Schema, ignoreUnsupportedCanonicalValues)); + if(jArr != null) attributes.AddRange(BuildAttributes(jArr, record.SchemaAttribute, record.Schema, ignoreUnsupportedCanonicalValues)); } else { @@ -908,12 +907,14 @@ private static ResolutionRowResult Resolve(KeyValuePair kvp, ICo private static ICollection ResolveFullQualifiedName(KeyValuePair kvp, ICollection extensionSchemas) { var jObj = kvp.Value as JObject; - if (jObj == null) + var jArr = kvp.Value as JArray; + if (jArr != null) { throw new SCIMSchemaViolatedException(string.Format(Global.PropertyCannotContainsArray, kvp.Key)); } var result = new List(); + if (jObj == null) return result; var schema = extensionSchemas.First(e => kvp.Key == e.Id); foreach (var skvp in jObj) {