Beispiel #1
0
        protected virtual void BuildScimRepresentationAttribute(string attributeId, SCIMRepresentation targetRepresentation, SCIMRepresentation sourceRepresentation, string sourceResourceType)
        {
            var rootSchema            = targetRepresentation.GetRootSchema();
            var attributes            = new List <SCIMRepresentationAttribute>();
            var targetSchemaAttribute = rootSchema.GetAttributeById(attributeId);
            var values  = rootSchema.GetChildren(targetSchemaAttribute);
            var value   = values.FirstOrDefault(s => s.Name == "value");
            var display = values.FirstOrDefault(s => s.Name == "display");
            var type    = values.FirstOrDefault(s => s.Name == "type");

            if (value != null)
            {
                attributes.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), value, value.SchemaId)
                {
                    ValueString = sourceRepresentation.Id
                });
            }

            if (display != null)
            {
                attributes.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), display, display.SchemaId)
                {
                    ValueString = sourceRepresentation.DisplayName
                });
            }

            if (type != null)
            {
                attributes.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), type, type.SchemaId)
                {
                    ValueString = sourceResourceType
                });
            }

            var attrId = Guid.NewGuid().ToString();
            var attrs  = targetRepresentation.GetAttributesByAttrSchemaId(targetSchemaAttribute.Id);

            if (attrs.Any())
            {
                attrId = attrs.First().AttributeId;
            }

            var parentAttr = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attrId, targetSchemaAttribute, targetSchemaAttribute.SchemaId)
            {
                SchemaAttribute = targetSchemaAttribute
            };

            targetRepresentation.AddAttribute(parentAttr);
            foreach (var attr in attributes)
            {
                targetRepresentation.AddAttribute(parentAttr, attr);
            }
        }
        public SCIMRepresentationBuilder AddComplexAttribute(string name, string schemaId, Action <SCIMRepresentationAttributeBuilder> callback)
        {
            var id              = Guid.NewGuid().ToString();
            var schema          = _schemas.First(s => s.Id == schemaId);
            var schemaAttribute = schema.Attributes.FirstOrDefault(a => a.Name == name);
            var builder         = new SCIMRepresentationAttributeBuilder(id, schema, schemaAttribute);

            callback(builder);
            var newAttribute = new SCIMRepresentationAttribute(id, Guid.NewGuid().ToString(), schemaAttribute, schemaId);

            foreach (var subAttribute in builder.Build())
            {
                _representation.AddAttribute(subAttribute);
            }

            _attributes.Add(newAttribute);
            return(this);
        }
Beispiel #3
0
        public void When_Parse_And_Execute_Filter()
        {
            var customSchema = SCIMSchemaBuilder.Create("urn:ietf:params:scim:schemas:core:2.0:CustomProperties", "User", SCIMEndpoints.User, "Custom properties", false)
                               .AddDecimalAttribute("age")
                               .AddBinaryAttribute("eidCertificate")
                               .AddStringAttribute("filePath")
                               .Build();
            var schema         = StandardSchemas.UserSchema;
            var representation = new SCIMRepresentation
            {
                Id           = Guid.NewGuid().ToString(),
                LastModified = DateTime.Parse("2010-05-13T04:42:34Z")
            };
            var secondRepresentation = new SCIMRepresentation
            {
                Id           = Guid.NewGuid().ToString(),
                LastModified = DateTime.Parse("2012-05-13T04:42:34Z"),
                Version      = 2
            };
            var thirdRepresentation = new SCIMRepresentation
            {
                Id = Guid.NewGuid().ToString()
            };

            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("title"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "title"
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), customSchema.GetAttribute("age"), customSchema.Id)
            {
                Id           = Guid.NewGuid().ToString(),
                ValueDecimal = 20
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), customSchema.GetAttribute("eidCertificate"), customSchema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueBinary = "aGVsbG8="
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), customSchema.GetAttribute("filePath"), customSchema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = @"C:\Program Files (x86)\Internet Explorer"
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("userType"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "Employee"
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("emails"), schema.Id));
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("emails.value"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "example.org"
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("emails.type"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "work"
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("phoneNumbers"), schema.Id));
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("phoneNumbers.primary"), schema.Id)
            {
                ValueBoolean = true
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("userName"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "bjensen"
            });
            representation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("name.familyName"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "O'Malley"
            });
            secondRepresentation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("userName"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "Justine"
            });
            secondRepresentation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("userType"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "Intern"
            });
            thirdRepresentation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("userName"), schema.Id)
            {
                Id          = Guid.NewGuid().ToString(),
                ValueString = "Jule"
            });
            thirdRepresentation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("ims"), schema.Id));
            thirdRepresentation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("ims.type"), schema.Id)
            {
                ValueString = "xmpp"
            });
            thirdRepresentation.AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schema.GetAttribute("ims.value"), schema.Id)
            {
                ValueString = "foo.com"
            });
            var representations = new List <SCIMRepresentation>
            {
                representation,
                secondRepresentation,
                thirdRepresentation
            };

            var firstResult     = ParseAndExecuteFilter(representations.AsQueryable(), "userName eq \"bjensen\"", customSchema);
            var secondResult    = ParseAndExecuteFilter(representations.AsQueryable(), "name.familyName co \"O'Malley\"", customSchema);
            var thirdResult     = ParseAndExecuteFilter(representations.AsQueryable(), "userName sw \"J\"", customSchema);
            var fourthResult    = ParseAndExecuteFilter(representations.AsQueryable(), "title pr", customSchema);
            var fifthResult     = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified gt \"2011-05-13T04:42:34Z\"", customSchema);
            var sixResult       = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified ge \"2011-05-13T04:42:34Z\"", customSchema);
            var sevenResult     = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified lt \"2011-05-13T04:42:34Z\"", customSchema);
            var eightResult     = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified le \"2011-05-13T04:42:34Z\"", customSchema);
            var nineResult      = ParseAndExecuteFilter(representations.AsQueryable(), "title pr and userType eq \"Employee\"", customSchema);
            var tenResult       = ParseAndExecuteFilter(representations.AsQueryable(), "title pr or userType eq \"Intern\"", customSchema);
            var elevenResult    = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and (emails.value co \"example.org\" or emails.value co \"example.org\")", customSchema);
            var twelveResult    = ParseAndExecuteFilter(representations.AsQueryable(), "userType ne \"Employee\" and not (emails co \"example.com\" or emails.value co \"example.org\")", customSchema);
            var thirteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and (emails.type eq \"work\")", customSchema);
            var fourteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and emails[type eq \"work\" and value co \"example.org\"]", customSchema);
            var fifteenResult   = ParseAndExecuteFilter(representations.AsQueryable(), "emails[type eq \"work\" and value co \"example.org\"] or ims[type eq \"xmpp\" and value co \"foo.com\"]", customSchema);
            var sixteenResult   = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified gt \"2011-05-13T04:42:34Z\" and meta.version eq \"2\"", customSchema);
            var seventeenResult = ParseAndExecuteFilter(representations.AsQueryable(), "phoneNumbers[primary eq \"true\"]", customSchema);
            var eighteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "age gt 15", customSchema);
            var nineteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "eidCertificate eq \"aGVsbG8=\"", customSchema);
            var twentyResult    = ParseAndExecuteFilter(representations.AsQueryable(), "filePath eq \"C:\\Program Files (x86)\\Internet Explorer\"", customSchema);
            var twentyOneResult = ParseAndExecuteFilter(representations.AsQueryable(), "urn:ietf:params:scim:schemas:core:2.0:User:userName eq \"bjensen\"", customSchema);
            var thirtyResult    = ParseAndExecuteFilter(representations.AsQueryable(), "urn:ietf:params:scim:schemas:core:2.0:User:name.familyName co \"O'Malley\"", customSchema);

            Assert.Equal(1, firstResult.Count());
            Assert.Equal(1, secondResult.Count());
            Assert.Equal(2, thirdResult.Count());
            Assert.Equal(1, fourthResult.Count());
            Assert.Equal(1, fifthResult.Count());
            Assert.Equal(1, sixResult.Count());
            Assert.Equal(2, sevenResult.Count());
            Assert.Equal(2, eightResult.Count());
            Assert.Equal(1, nineResult.Count());
            Assert.Equal(2, tenResult.Count());
            Assert.Equal(1, elevenResult.Count());
            Assert.Equal(1, twelveResult.Count());
            Assert.Equal(1, thirteenResult.Count());
            Assert.Equal(1, fourteenResult.Count());
            Assert.Equal(2, fifteenResult.Count());
            Assert.Equal(1, sixteenResult.Count());
            Assert.Equal(1, seventeenResult.Count());
            Assert.Equal(1, eighteenResult.Count());
            Assert.Equal(1, nineteenResult.Count());
            Assert.Equal(1, twentyResult.Count());
            Assert.Equal(1, twentyOneResult.Count());
            Assert.Equal(1, thirtyResult.Count());
        }