public static SCIMSchemaAttributeModel ToModel(this SCIMSchemaAttribute schemaAttribute, string schemaId)
        {
            var result = new SCIMSchemaAttributeModel
            {
                Id                 = schemaAttribute.Id,
                SchemaId           = schemaId,
                CanonicalValues    = schemaAttribute.CanonicalValues == null ? new List <string>() : schemaAttribute.CanonicalValues.ToList(),
                CaseExact          = schemaAttribute.CaseExact,
                DefaultValueInt    = schemaAttribute.DefaultValueInt.ToList(),
                DefaultValueString = schemaAttribute.DefaultValueString.ToList(),
                Description        = schemaAttribute.Description,
                MultiValued        = schemaAttribute.MultiValued,
                Mutability         = schemaAttribute.Mutability,
                Name               = schemaAttribute.Name,
                ReferenceTypes     = schemaAttribute.ReferenceTypes.ToList(),
                Required           = schemaAttribute.Required,
                Returned           = schemaAttribute.Returned,
                Type               = schemaAttribute.Type,
                Uniqueness         = schemaAttribute.Uniqueness,
                SubAttributes      = new List <SCIMSchemaAttributeModel>()
            };

            if (schemaAttribute.SubAttributes.Any())
            {
                foreach (var subAttr in schemaAttribute.SubAttributes.ToList())
                {
                    result.SubAttributes.Add(ToModel(subAttr, schemaId));
                }
            }

            return(result);
        }
 public SCIMSchemaAttributeBuilder(string parentId, string fullPath, SCIMSchema schema, SCIMSchemaAttribute scimSchemaAttribute)
 {
     _schema = schema;
     _scimSchemaAttribute = scimSchemaAttribute;
     _fullPath = fullPath;
     _parentId = parentId;
 }
        private static JObject SerializeSCIMSchemaAttribute(SCIMSchemaAttribute scimSchemaAttribute)
        {
            var result = new JObject();

            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Name, scimSchemaAttribute.Name);
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Type, scimSchemaAttribute.Type.ToString().ToLowerInvariant());
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.MultiValued, scimSchemaAttribute.MultiValued);
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Description, scimSchemaAttribute.Description);
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Required, scimSchemaAttribute.Required);
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.CaseExact, scimSchemaAttribute.CaseExact);
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Mutability, scimSchemaAttribute.Mutability.ToString().ToLowerInvariant());
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Returned, scimSchemaAttribute.Returned.ToString().ToLowerInvariant());
            result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Uniqueness, scimSchemaAttribute.Uniqueness.ToString().ToLowerInvariant());
            if (scimSchemaAttribute.SubAttributes != null && scimSchemaAttribute.SubAttributes.Any())
            {
                var subAttributes = new JArray();
                foreach (var subAttribute in scimSchemaAttribute.SubAttributes)
                {
                    subAttributes.Add(SerializeSCIMSchemaAttribute(subAttribute));
                }

                result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.SubAttributes, subAttributes);
            }

            return(result);
        }
 public SCIMRepresentationAttributeBuilder(string parentId, SCIMSchema schema, SCIMSchemaAttribute scimSchemaAttribute)
 {
     _schema              = schema;
     _parentId            = parentId;
     _scimSchemaAttribute = scimSchemaAttribute;
     _attributes          = new List <SCIMRepresentationAttribute>();
 }
        public static SCIMSchemaAttribute ToDomain(this SCIMSchemaAttributeModel schemaAttribute)
        {
            var result = new SCIMSchemaAttribute(schemaAttribute.Id)
            {
                CanonicalValues    = schemaAttribute.CanonicalValues.ToList(),
                CaseExact          = schemaAttribute.CaseExact,
                DefaultValueInt    = schemaAttribute.DefaultValueInt.ToList(),
                DefaultValueString = schemaAttribute.DefaultValueString.ToList(),
                Description        = schemaAttribute.Description,
                MultiValued        = schemaAttribute.MultiValued,
                Mutability         = schemaAttribute.Mutability,
                Name           = schemaAttribute.Name,
                ReferenceTypes = schemaAttribute.ReferenceTypes.ToList(),
                Required       = schemaAttribute.Required,
                Returned       = schemaAttribute.Returned,
                Type           = schemaAttribute.Type,
                Uniqueness     = schemaAttribute.Uniqueness
            };

            if (schemaAttribute.SubAttributes != null && schemaAttribute.SubAttributes.Any())
            {
                foreach (var subAttr in schemaAttribute.SubAttributes.ToList())
                {
                    result.AddSubAttribute(ToDomain(subAttr));
                }
            }

            return(result);
        }
Beispiel #6
0
        public SCIMRepresentationAttributeBuilder AddAttribute(string name, List <int> valuesInt = null, List <bool> valuesBool = null, List <string> valuesString = null, List <DateTime> valuesDateTime = null)
        {
            var id = Guid.NewGuid().ToString();
            SCIMSchemaAttribute schemaAttribute = null;

            if (_scimSchemaAttribute != null && _scimSchemaAttribute.SubAttributes != null)
            {
                schemaAttribute = _scimSchemaAttribute.SubAttributes.FirstOrDefault(a => a.Name == name);
            }

            _attributes.Add(new SCIMRepresentationAttribute(id, schemaAttribute, valuesInt, valuesBool, valuesString, valuesDateTime));
            return(this);
        }
Beispiel #7
0
 public ResolutionRowResult(SCIMSchema schema, SCIMSchemaAttribute schemaAttribute, JToken content) : this(schemaAttribute, content)
 {
     Schema = schema;
 }
Beispiel #8
0
 public ResolutionRowResult(SCIMSchemaAttribute schemaAttribute, JToken content)
 {
     SchemaAttribute = schemaAttribute;
     Content         = content;
 }
Beispiel #9
0
        public static ICollection <SCIMRepresentationAttribute> BuildAttributes(JArray jArr, SCIMSchemaAttribute schemaAttribute, SCIMSchema schema, bool ignoreUnsupportedCanonicalValues)
        {
            var result = new List <SCIMRepresentationAttribute>();

            if (schemaAttribute.Mutability == SCIMSchemaAttributeMutabilities.READONLY)
            {
                return(result);
            }

            var attributeId = Guid.NewGuid().ToString();

            if (schemaAttribute.Type == SCIMSchemaAttributeTypes.COMPLEX)
            {
                if (!jArr.Any())
                {
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id));
                }
                else
                {
                    foreach (var jsonProperty in jArr)
                    {
                        var rec = jsonProperty as JObject;
                        if (rec == null)
                        {
                            throw new SCIMSchemaViolatedException(string.Format(Global.NotValidJSON, jsonProperty.ToString()));
                        }

                        var subAttributes = schema.GetChildren(schemaAttribute).ToList();
                        CheckRequiredAttributes(schema, subAttributes, rec);
                        var resolutionResult = Resolve(rec, schema, subAttributes);
                        var parent           = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id);
                        var children         = BuildRepresentationAttributes(resolutionResult, subAttributes, ignoreUnsupportedCanonicalValues);
                        foreach (var child in children)
                        {
                            if (SCIMRepresentation.GetParentPath(child.FullPath) == parent.FullPath)
                            {
                                child.ParentAttributeId = parent.Id;
                            }

                            result.Add(child);
                        }

                        result.Add(parent);
                    }
                }
            }
            else
            {
                switch (schemaAttribute.Type)
                {
                case SCIMSchemaAttributeTypes.BOOLEAN:
                    var valuesBooleanResult = Extract <bool>(jArr);
                    if (valuesBooleanResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidBoolean, string.Join(",", valuesBooleanResult.InvalidValues)));
                    }

                    foreach (var b in valuesBooleanResult.Values)
                    {
                        var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueBoolean: b);
                        result.Add(record);
                    }
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    var valuesIntegerResult = Extract <int>(jArr);
                    if (valuesIntegerResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidInteger, string.Join(",", valuesIntegerResult.InvalidValues)));
                    }

                    foreach (var i in valuesIntegerResult.Values)
                    {
                        var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueInteger: i);
                        result.Add(record);
                    }
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    var valuesDateTimeResult = Extract <DateTime>(jArr);
                    if (valuesDateTimeResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidDateTime, string.Join(",", valuesDateTimeResult.InvalidValues)));
                    }

                    foreach (var d in valuesDateTimeResult.Values)
                    {
                        var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueDateTime: d);
                        result.Add(record);
                    }
                    break;

                case SCIMSchemaAttributeTypes.STRING:
                    var strs = jArr.Select(j => j.ToString()).ToList();
                    if (schemaAttribute.CanonicalValues != null &&
                        schemaAttribute.CanonicalValues.Any() &&
                        !ignoreUnsupportedCanonicalValues &&
                        !strs.All(_ => schemaAttribute.CaseExact ?
                                  schemaAttribute.CanonicalValues.Contains(_)
                                : schemaAttribute.CanonicalValues.Contains(_, StringComparer.OrdinalIgnoreCase))
                        )
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidCanonicalValue, schemaAttribute.Name));
                    }

                    foreach (var s in strs)
                    {
                        var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueString: s);
                        result.Add(record);
                    }
                    break;

                case SCIMSchemaAttributeTypes.REFERENCE:
                    var refs = jArr.Select(j => j.ToString()).ToList();
                    foreach (var reference in refs)
                    {
                        var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueReference: reference);
                        result.Add(record);
                    }
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    var valuesDecimalResult = Extract <decimal>(jArr);
                    if (valuesDecimalResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidDecimal, string.Join(",", valuesDecimalResult.InvalidValues)));
                    }

                    foreach (var d in valuesDecimalResult.Values)
                    {
                        var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueDecimal: d);
                        result.Add(record);
                    }
                    break;

                case SCIMSchemaAttributeTypes.BINARY:
                    var invalidValues = new List <string>();
                    var valuesBinary  = new List <string>();
                    foreach (var rec in jArr)
                    {
                        try
                        {
                            Convert.FromBase64String(rec.ToString());
                            valuesBinary.Add(rec.ToString());
                        }
                        catch (FormatException)
                        {
                            invalidValues.Add(rec.ToString());
                        }
                    }

                    if (invalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidBase64, string.Join(",", invalidValues)));
                    }

                    foreach (var b in valuesBinary)
                    {
                        var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueBinary: b);
                        result.Add(record);
                    }
                    break;
                }
            }

            return(result);
        }
Beispiel #10
0
 public SCIMRepresentationAttributeBuilder(SCIMSchemaAttribute scimSchemaAttribute)
 {
     _scimSchemaAttribute = scimSchemaAttribute;
     _attributes          = new List <SCIMRepresentationAttribute>();
 }
Beispiel #11
0
        private static ICollection <SCIMRepresentationAttribute> BuildAttributes(JArray jArr, SCIMSchemaAttribute schemaAttribute)
        {
            var result = new List <SCIMRepresentationAttribute>();

            if (schemaAttribute.Type == SCIMSchemaAttributeTypes.COMPLEX)
            {
                foreach (var jsonProperty in jArr)
                {
                    var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute)
                    {
                        Values = BuildRepresentationAttributes(jsonProperty as JObject, schemaAttribute.SubAttributes)
                    };
                    result.Add(record);
                }
            }
            else
            {
                var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute);
                switch (schemaAttribute.Type)
                {
                case SCIMSchemaAttributeTypes.BOOLEAN:
                    record.ValuesBoolean = jArr.Select(j => bool.Parse(j.ToString())).ToList();
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    record.ValuesInteger = jArr.Select(j => int.Parse(j.ToString())).ToList();
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    record.ValuesDateTime = jArr.Select(j => DateTime.Parse(j.ToString())).ToList();
                    break;

                case SCIMSchemaAttributeTypes.STRING:
                    record.ValuesString = jArr.Select(j => j.ToString()).ToList();
                    break;

                case SCIMSchemaAttributeTypes.REFERENCE:
                    record.ValuesReference = jArr.Select(j => j.ToString()).ToList();
                    break;
                }

                result.Add(record);
            }

            return(result);
        }
 public SCIMSchemaAttributeBuilder(SCIMSchemaAttribute scimSchemaAttribute)
 {
     _scimSchemaAttribute = scimSchemaAttribute;
 }
        private static Expression BuildComparisonExpression(
            SCIMComparisonExpression comparisonExpression,
            SCIMSchemaAttribute schemaAttr,
            MemberExpression propertyValueString        = null,
            MemberExpression propertyValueInteger       = null,
            MemberExpression propertyValueDatetime      = null,
            MemberExpression propertyValueBoolean       = null,
            MemberExpression propertyValueDecimal       = null,
            MemberExpression propertyValueBinary        = null,
            ParameterExpression representationParameter = null)
        {
            representationParameter = representationParameter ?? Expression.Parameter(typeof(SCIMRepresentationAttribute), "ra");
            propertyValueString     = propertyValueString ?? Expression.Property(representationParameter, "ValueString");
            propertyValueInteger    = propertyValueInteger ?? Expression.Property(representationParameter, "ValueInteger");
            propertyValueDatetime   = propertyValueDatetime ?? Expression.Property(representationParameter, "ValueDateTime");
            propertyValueBoolean    = propertyValueBoolean ?? Expression.Property(representationParameter, "ValueBoolean");
            propertyValueDecimal    = propertyValueDecimal ?? Expression.Property(representationParameter, "ValueDecimal");
            propertyValueBinary     = propertyValueBinary ?? Expression.Property(representationParameter, "ValueBinary");
            Expression comparison = null;

            switch (comparisonExpression.ComparisonOperator)
            {
            case SCIMComparisonOperators.NE:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.STRING:
                    comparison = NotEqual(propertyValueString, Expression.Constant(comparisonExpression.Value));
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    comparison = NotEqual(propertyValueInteger, Expression.Constant(ParseInt(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    comparison = NotEqual(propertyValueDatetime, Expression.Constant(ParseDateTime(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.BOOLEAN:
                    comparison = NotEqual(propertyValueBoolean, Expression.Constant(ParseBoolean(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    comparison = NotEqual(propertyValueDecimal, Expression.Constant(ParseDecimal(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.BINARY:
                    comparison = NotEqual(propertyValueBinary, Expression.Constant(comparisonExpression.Value));
                    break;
                }
                break;

            case SCIMComparisonOperators.GT:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.INTEGER:
                    comparison = GreaterThan(propertyValueInteger, Expression.Constant(ParseInt(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    comparison = GreaterThan(propertyValueDatetime, Expression.Constant(ParseDateTime(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    comparison = GreaterThan(propertyValueDecimal, Expression.Constant(ParseDecimal(comparisonExpression.Value)));
                    break;
                }
                break;

            case SCIMComparisonOperators.GE:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.INTEGER:
                    comparison = GreaterThanOrEqual(propertyValueInteger, Expression.Constant(ParseInt(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    comparison = GreaterThanOrEqual(propertyValueDatetime, Expression.Constant(ParseDateTime(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    comparison = GreaterThanOrEqual(propertyValueDecimal, Expression.Constant(ParseDecimal(comparisonExpression.Value)));
                    break;
                }
                break;

            case SCIMComparisonOperators.LE:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.INTEGER:
                    comparison = LessThanOrEqual(propertyValueInteger, Expression.Constant(ParseInt(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    comparison = LessThanOrEqual(propertyValueDatetime, Expression.Constant(ParseDateTime(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    comparison = LessThanOrEqual(propertyValueDecimal, Expression.Constant(ParseDecimal(comparisonExpression.Value)));
                    break;
                }
                break;

            case SCIMComparisonOperators.LT:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.INTEGER:
                    comparison = LessThan(propertyValueInteger, Expression.Constant(ParseInt(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    comparison = LessThan(propertyValueDatetime, Expression.Constant(ParseDateTime(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    comparison = LessThan(propertyValueDecimal, Expression.Constant(ParseDecimal(comparisonExpression.Value)));
                    break;
                }
                break;

            case SCIMComparisonOperators.EQ:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.STRING:
                    comparison = Equal(propertyValueString, Expression.Constant(comparisonExpression.Value));
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    comparison = Equal(propertyValueInteger, Expression.Constant(ParseInt(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    comparison = Equal(propertyValueDatetime, Expression.Constant(ParseDateTime(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.BOOLEAN:
                    comparison = Equal(propertyValueBoolean, Expression.Constant(ParseBoolean(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    comparison = Equal(propertyValueDecimal, Expression.Constant(ParseDecimal(comparisonExpression.Value)));
                    break;

                case SCIMSchemaAttributeTypes.BINARY:
                    comparison = Equal(propertyValueBinary, Expression.Constant(comparisonExpression.Value));
                    break;
                }
                break;

            case SCIMComparisonOperators.SW:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.STRING:
                    var startWith = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
                    comparison = Expression.Call(propertyValueString, startWith, Expression.Constant(comparisonExpression.Value));
                    break;
                }
                break;

            case SCIMComparisonOperators.EW:
                switch (schemaAttr.Type)
                {
                case SCIMSchemaAttributeTypes.STRING:
                    var endWith = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) });
                    comparison = Expression.Call(propertyValueString, endWith, Expression.Constant(comparisonExpression.Value));
                    break;
                }
                break;

            case SCIMComparisonOperators.CO:
                if (schemaAttr.Type == SCIMSchemaAttributeTypes.STRING)
                {
                    var contains = typeof(string).GetMethod("Contains", new[] { typeof(string) });
                    comparison = Expression.Call(propertyValueString, contains, Expression.Constant(comparisonExpression.Value));
                }
                break;
            }

            return(comparison);
        }
        private static Expression Evaluate(this SCIMComparisonExpression comparisonExpression, ParameterExpression parameterExpression)
        {
            bool isMetadata = false;
            var  lastChild  = comparisonExpression.LeftExpression.GetLastChild();
            var  fullPath   = comparisonExpression.LeftExpression.GetFullPath();
            var  representationParameter = Expression.Parameter(typeof(SCIMRepresentationAttribute), "ra");
            var  propertySchemaAttribute = Expression.Property(representationParameter, "SchemaAttributeId");
            var  propertyValueString     = Expression.Property(representationParameter, "ValueString");
            var  propertyValueInteger    = Expression.Property(representationParameter, "ValueInteger");
            var  propertyValueDatetime   = Expression.Property(representationParameter, "ValueDateTime");
            var  schemaAttr = lastChild.SchemaAttribute;

            if (ParserConstants.MappingStandardAttributePathToProperty.ContainsKey(fullPath))
            {
                isMetadata = true;
                var name = ParserConstants.MappingStandardAttributePathToProperty[fullPath];
                var type = ParserConstants.MappingStandardAttributeTypeToType[fullPath];
                switch (type)
                {
                case SCIMSchemaAttributeTypes.STRING:
                    propertyValueString = Expression.Property(parameterExpression, name);
                    schemaAttr          = new SCIMSchemaAttribute(Guid.NewGuid().ToString())
                    {
                        Type = SCIMSchemaAttributeTypes.STRING
                    };
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    propertyValueInteger = Expression.Property(parameterExpression, name);
                    schemaAttr           = new SCIMSchemaAttribute(Guid.NewGuid().ToString())
                    {
                        Type = SCIMSchemaAttributeTypes.INTEGER
                    };
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    propertyValueDatetime = Expression.Property(parameterExpression, name);
                    schemaAttr            = new SCIMSchemaAttribute(Guid.NewGuid().ToString())
                    {
                        Type = SCIMSchemaAttributeTypes.DATETIME
                    };
                    break;
                }
            }

            var attributes = Expression.Property(parameterExpression, "FlatAttributes");
            var comparison = BuildComparisonExpression(comparisonExpression,
                                                       schemaAttr,
                                                       propertyValueString,
                                                       propertyValueInteger,
                                                       propertyValueDatetime,
                                                       representationParameter: representationParameter);

            if (isMetadata)
            {
                return(comparison);
            }

            var body = Expression.Lambda <Func <SCIMRepresentationAttribute, bool> >(
                Expression.AndAlso(Expression.Equal(propertySchemaAttribute, Expression.Constant(schemaAttr.Id)), comparison),
                representationParameter);
            var anyMethodType = typeof(Enumerable).GetMethods().First(m => m.Name == "Any" && m.GetParameters().Length == 2).MakeGenericMethod(typeof(SCIMRepresentationAttribute));

            return(Expression.Call(anyMethodType, attributes, body));
        }
        public static ICollection <SCIMRepresentationAttribute> BuildAttributes(JArray jArr, SCIMSchemaAttribute schemaAttribute, SCIMSchema schema, bool ignoreUnsupportedCanonicalValues)
        {
            var result = new List <SCIMRepresentationAttribute>();

            if (schemaAttribute.Type == SCIMSchemaAttributeTypes.COMPLEX)
            {
                if (!jArr.Any())
                {
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute));
                }
                else
                {
                    foreach (var jsonProperty in jArr)
                    {
                        var rec = jsonProperty as JObject;
                        if (rec == null)
                        {
                            throw new SCIMSchemaViolatedException(string.Format(Global.NotValidJSON, jsonProperty.ToString()));
                        }

                        CheckRequiredAttributes(schema, schemaAttribute.SubAttributes, rec);
                        var resolutionResult = Resolve(rec, schema, schemaAttribute.SubAttributes);
                        var record           = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute)
                        {
                            Values = BuildRepresentationAttributes(resolutionResult, schemaAttribute.SubAttributes, ignoreUnsupportedCanonicalValues)
                        };

                        foreach (var subAttribute in record.Values)
                        {
                            subAttribute.Parent = record;
                        }

                        result.Add(record);
                    }
                }
            }
            else
            {
                var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute);
                switch (schemaAttribute.Type)
                {
                case SCIMSchemaAttributeTypes.BOOLEAN:
                    var valuesBooleanResult = Extract <bool>(jArr);
                    if (valuesBooleanResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidBoolean, string.Join(",", valuesBooleanResult.InvalidValues)));
                    }

                    record.ValuesBoolean = valuesBooleanResult.Values;
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    var valuesIntegerResult = Extract <int>(jArr);
                    if (valuesIntegerResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidInteger, string.Join(",", valuesIntegerResult.InvalidValues)));
                    }

                    record.ValuesInteger = valuesIntegerResult.Values;
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    var valuesDateTimeResult = Extract <DateTime>(jArr);
                    if (valuesDateTimeResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidDateTime, string.Join(",", valuesDateTimeResult.InvalidValues)));
                    }

                    record.ValuesDateTime = valuesDateTimeResult.Values;
                    break;

                case SCIMSchemaAttributeTypes.STRING:
                    record.ValuesString = jArr.Select(j => j.ToString()).ToList();
                    if (schemaAttribute.CanonicalValues != null && schemaAttribute.CanonicalValues.Any() && !ignoreUnsupportedCanonicalValues && !record.ValuesString.All(_ => schemaAttribute.CanonicalValues.Contains(_)))
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidCanonicalValue, schemaAttribute.Name));
                    }

                    break;

                case SCIMSchemaAttributeTypes.REFERENCE:
                    record.ValuesReference = jArr.Select(j => j.ToString()).ToList();
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    var valuesDecimalResult = Extract <decimal>(jArr);
                    if (valuesDecimalResult.InvalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidDecimal, string.Join(",", valuesDecimalResult.InvalidValues)));
                    }

                    record.ValuesDecimal = valuesDecimalResult.Values;
                    break;

                case SCIMSchemaAttributeTypes.BINARY:
                    var invalidValues = new List <string>();
                    var valuesBinary  = new List <byte[]>();
                    foreach (var rec in jArr)
                    {
                        try
                        {
                            valuesBinary.Add(Convert.FromBase64String(rec.ToString()));
                        }
                        catch (FormatException)
                        {
                            invalidValues.Add(rec.ToString());
                        }
                    }

                    if (invalidValues.Any())
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidBase64, string.Join(",", invalidValues)));
                    }

                    record.ValuesBinary = valuesBinary;
                    break;
                }

                result.Add(record);
            }

            return(result);
        }
        public SCIMRepresentationAttributeBuilder AddAttribute(string name, List <int> valuesInt = null, List <bool> valuesBool = null, List <string> valuesString = null, List <DateTime> valuesDateTime = null, List <decimal> valuesDecimal = null, List <string> valuesBinary = null)
        {
            var id = Guid.NewGuid().ToString();
            SCIMSchemaAttribute schemaAttribute = null;
            var subAttributes = _schema.GetChildren(_scimSchemaAttribute);

            if (subAttributes != null)
            {
                schemaAttribute = subAttributes.FirstOrDefault(a => a.Name == name);
            }

            var attributeId = Guid.NewGuid().ToString();

            if (valuesInt != null)
            {
                foreach (var attr in valuesInt)
                {
                    _attributes.Add(new SCIMRepresentationAttribute(id, attributeId, schemaAttribute, schemaAttribute.SchemaId, valueInteger: attr)
                    {
                        ParentAttributeId = _parentId
                    });
                }
            }
            else if (valuesBool != null)
            {
                foreach (var attr in valuesBool)
                {
                    _attributes.Add(new SCIMRepresentationAttribute(id, attributeId, schemaAttribute, schemaAttribute.SchemaId, valueBoolean: attr)
                    {
                        ParentAttributeId = _parentId
                    });
                }
            }
            else if (valuesString != null)
            {
                foreach (var attr in valuesString)
                {
                    _attributes.Add(new SCIMRepresentationAttribute(id, attributeId, schemaAttribute, schemaAttribute.SchemaId, valueString: attr)
                    {
                        ParentAttributeId = _parentId
                    });
                }
            }
            else if (valuesDateTime != null)
            {
                foreach (var attr in valuesDateTime)
                {
                    _attributes.Add(new SCIMRepresentationAttribute(id, attributeId, schemaAttribute, schemaAttribute.SchemaId, valueDateTime: attr)
                    {
                        ParentAttributeId = _parentId
                    });
                }
            }
            else if (valuesDecimal != null)
            {
                foreach (var attr in valuesDecimal)
                {
                    _attributes.Add(new SCIMRepresentationAttribute(id, attributeId, schemaAttribute, schemaAttribute.SchemaId, valueDecimal: attr)
                    {
                        ParentAttributeId = _parentId
                    });
                }
            }
            else if (valuesBinary != null)
            {
                foreach (var attr in valuesBinary)
                {
                    _attributes.Add(new SCIMRepresentationAttribute(id, attributeId, schemaAttribute, schemaAttribute.SchemaId, valueBinary: attr)
                    {
                        ParentAttributeId = _parentId
                    });
                }
            }

            return(this);
        }
Beispiel #17
0
        public static ICollection <SCIMRepresentationAttribute> BuildAttributes(JArray jArr, SCIMSchemaAttribute schemaAttribute, bool ignoreUnsupportedCanonicalValues)
        {
            var result = new List <SCIMRepresentationAttribute>();

            if (schemaAttribute.Type == SCIMSchemaAttributeTypes.COMPLEX)
            {
                foreach (var jsonProperty in jArr)
                {
                    var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute)
                    {
                        Values = BuildRepresentationAttributes(jsonProperty as JObject, schemaAttribute.SubAttributes, ignoreUnsupportedCanonicalValues)
                    };

                    foreach (var subAttribute in record.Values)
                    {
                        subAttribute.Parent = record;
                    }

                    result.Add(record);
                }
            }
            else
            {
                var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute);
                switch (schemaAttribute.Type)
                {
                case SCIMSchemaAttributeTypes.BOOLEAN:
                    record.ValuesBoolean = jArr.Select(j => bool.Parse(j.ToString())).ToList();
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    record.ValuesInteger = jArr.Select(j => int.Parse(j.ToString())).ToList();
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    record.ValuesDateTime = jArr.Select(j => DateTime.Parse(j.ToString())).ToList();
                    break;

                case SCIMSchemaAttributeTypes.STRING:
                    record.ValuesString = jArr.Select(j => j.ToString()).ToList();
                    if (schemaAttribute.CanonicalValues != null && schemaAttribute.CanonicalValues.Any() && !ignoreUnsupportedCanonicalValues && !record.ValuesString.All(_ => schemaAttribute.CanonicalValues.Contains(_)))
                    {
                        throw new SCIMSchemaViolatedException(string.Format(Global.NotValidCanonicalValue, schemaAttribute.Name));
                    }

                    break;

                case SCIMSchemaAttributeTypes.REFERENCE:
                    record.ValuesReference = jArr.Select(j => j.ToString()).ToList();
                    break;

                case SCIMSchemaAttributeTypes.DECIMAL:
                    record.ValuesDecimal = jArr.Select(j => decimal.Parse(j.ToString())).ToList();
                    break;

                case SCIMSchemaAttributeTypes.BINARY:
                    record.ValuesBinary = jArr.Select(j => Convert.FromBase64String(j.ToString())).ToList();
                    break;
                }

                result.Add(record);
            }

            return(result);
        }
Beispiel #18
0
        private static SCIMRepresentationAttribute BuildAttribute(JToken jsonProperty, SCIMSchemaAttribute schemaAttribute)
        {
            var result = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute);

            switch (schemaAttribute.Type)
            {
            case SCIMSchemaAttributeTypes.BOOLEAN:
                result.Add(bool.Parse(jsonProperty.ToString()));
                break;

            case SCIMSchemaAttributeTypes.INTEGER:
                result.Add(int.Parse(jsonProperty.ToString()));
                break;

            case SCIMSchemaAttributeTypes.DATETIME:
                result.Add(DateTime.Parse(jsonProperty.ToString()));
                break;

            case SCIMSchemaAttributeTypes.STRING:
                result.Add(jsonProperty.ToString());
                break;

            case SCIMSchemaAttributeTypes.COMPLEX:
                result.Values = BuildRepresentationAttributes(jsonProperty as JObject, schemaAttribute.SubAttributes);
                break;

            case SCIMSchemaAttributeTypes.REFERENCE:
                // REFERENCE.
                break;
            }

            return(result);
        }