Exemple #1
0
        public void When_Apply_Patch_To_SCIM_Representation()
        {
            var userSchema = SCIMSchemaBuilder.Create("urn:ietf:params:scim:schemas:core:2.0:User", "User", "User Account")
                             .AddStringAttribute("userName", caseExact: true, uniqueness: SCIMSchemaAttributeUniqueness.SERVER)
                             .AddComplexAttribute("phones", opt =>
            {
                opt.AddStringAttribute("phoneNumber", description: "Phone number");
                opt.AddStringAttribute("type", description: "Type");
            }, multiValued: true, mutability: SCIMSchemaAttributeMutabilities.READWRITE)
                             .Build();
            var userRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                userSchema
            })
                                     .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "john"
            })
                                     .AddComplexAttribute("phones", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("phoneNumber", new List <string> {
                    "01"
                });
                b.AddStringAttribute("type", new List <string> {
                    "mobile"
                });
            })
                                     .AddComplexAttribute("phones", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("phoneNumber", new List <string> {
                    "02"
                });
                b.AddStringAttribute("type", new List <string> {
                    "home"
                });
            })
                                     .Build();

            userRepresentation.ApplyPatches(new List <SCIMPatchOperationRequest>
            {
                new SCIMPatchOperationRequest(SCIMPatchOperations.REPLACE, "userName", "cassandra"),
                new SCIMPatchOperationRequest(SCIMPatchOperations.ADD, "phones", JArray.Parse("[{ phoneNumber : '03', type: 'type1' }, { phoneNumber : '05', type: 'type2' }]")),
                new SCIMPatchOperationRequest(SCIMPatchOperations.REMOVE, "phones[phoneNumber eq 01]")
            }, false);

            Assert.Equal("cassandra", userRepresentation.Attributes.First(a => a.SchemaAttribute.Name == "userName").ValuesString.First());
            Assert.True(userRepresentation.Attributes.Any(a => a.SchemaAttribute.Name == "phones" && a.Values.Any(b => b.SchemaAttribute.Name == "phoneNumber" && b.ValuesString.Contains("03"))) == true);
            Assert.True(userRepresentation.Attributes.Any(a => a.SchemaAttribute.Name == "phones" && a.Values.Any(b => b.SchemaAttribute.Name == "phoneNumber" && b.ValuesString.Contains("05"))) == true);
            Assert.True(userRepresentation.Attributes.Any(a => a.SchemaAttribute.Name == "phones" && a.Values.Any(b => b.SchemaAttribute.Name == "phoneNumber" && b.ValuesString.Contains("01"))) == false);
        }
Exemple #2
0
        public void When_Extract_Attributes()
        {
            var userSchema = SCIMSchemaBuilder.Create("urn:ietf:params:scim:schemas:core:2.0:User", "User", "User Account")
                             .AddStringAttribute("userName", caseExact: true, uniqueness: SCIMSchemaAttributeUniqueness.SERVER)
                             .AddComplexAttribute("phones", opt =>
            {
                opt.AddStringAttribute("phoneNumber", description: "Phone number");
                opt.AddStringAttribute("type", description: "Type");
            }, multiValued: true, mutability: SCIMSchemaAttributeMutabilities.READWRITE)
                             .Build();
            var userRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                userSchema
            })
                                     .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "john"
            })
                                     .AddComplexAttribute("phones", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("phoneNumber", new List <string> {
                    "01"
                });
                b.AddStringAttribute("type", new List <string> {
                    "mobile"
                });
            })
                                     .AddComplexAttribute("phones", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("phoneNumber", new List <string> {
                    "02"
                });
                b.AddStringAttribute("type", new List <string> {
                    "home"
                });
            })
                                     .Build();

            var firstFilter = SCIMFilterParser.Parse("phones.phoneNumber", new List <SCIMSchema> {
                userSchema
            });
            var secondFilter = SCIMFilterParser.Parse("phones[phoneNumber eq 02]", new List <SCIMSchema> {
                userSchema
            });
            var thirdFilter = SCIMFilterParser.Parse("userName", new List <SCIMSchema> {
                userSchema
            });
            var fourthFilter = SCIMFilterParser.Parse("phones.phoneNumber", new List <SCIMSchema> {
                userSchema
            });
            var fifthFilter = SCIMFilterParser.Parse("phones[phoneNumber eq 02]", new List <SCIMSchema> {
                userSchema
            });
            var sixFilter = SCIMFilterParser.Parse("meta.lastModified", new List <SCIMSchema> {
                userSchema
            });
            var sevenFilter = SCIMFilterParser.Parse("meta.lastModified", new List <SCIMSchema> {
                userSchema
            });
            var eightFilter = SCIMFilterParser.Parse("id", new List <SCIMSchema> {
                userSchema
            });
            var nineFilter = SCIMFilterParser.Parse("id", new List <SCIMSchema> {
                userSchema
            });

            var firstJSON = userRepresentation.ToResponseWithIncludedAttributes(new List <SCIMExpression> {
                firstFilter
            });
            var secondJSON = userRepresentation.ToResponseWithIncludedAttributes(new List <SCIMExpression> {
                secondFilter
            });
            var thirdJSON = userRepresentation.ToResponseWithExcludedAttributes(new List <SCIMExpression> {
                thirdFilter
            }, "http://localhost");
            var fourthJSON = userRepresentation.ToResponseWithExcludedAttributes(new List <SCIMExpression> {
                fourthFilter
            }, "http://localhost");
            var fifthJSON = userRepresentation.ToResponseWithExcludedAttributes(new List <SCIMExpression> {
                fifthFilter
            }, "http://localhost");
            var sixJSON = userRepresentation.ToResponseWithIncludedAttributes(new List <SCIMExpression> {
                sixFilter
            });
            var sevenJSON = userRepresentation.ToResponseWithExcludedAttributes(new List <SCIMExpression> {
                sevenFilter
            }, "http://localhost");
            var eightJSON = userRepresentation.ToResponseWithExcludedAttributes(new List <SCIMExpression> {
                eightFilter
            }, "http://localhost");
            var nineJSON = userRepresentation.ToResponseWithIncludedAttributes(new List <SCIMExpression> {
                nineFilter
            });

            Assert.Equal("01", firstJSON.SelectToken("phones[0].phoneNumber").ToString());
            Assert.Equal("02", secondJSON.SelectToken("phones[0].phoneNumber").ToString());
            Assert.Equal("home", secondJSON.SelectToken("phones[0].type").ToString());
            Assert.Null(thirdJSON.SelectToken("userName"));
            Assert.Null(fourthJSON.SelectToken("phones[0].phoneNumber"));
            Assert.True((fifthJSON.SelectToken("phones") as JArray).Count == 1);
            Assert.NotNull(sixJSON.SelectToken("meta.lastModified"));
            Assert.Null(sevenJSON.SelectToken("meta.lastModified"));
            Assert.NotNull(eightJSON.SelectToken("id"));
            Assert.NotNull(nineJSON.SelectToken("id"));
        }
        public void When_Parse_And_Execute_Filter()
        {
            var firstRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                SCIMConstants.StandardSchemas.UserSchema, SCIMConstants.StandardSchemas.CommonSchema
            })
                                      .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "bjensen"
            })
                                      .AddBooleanAttribute("active", "urn:ietf:params:scim:schemas:core:2.0:User", new List <bool> {
                true
            })
                                      .AddStringAttribute("title", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "title"
            })
                                      .AddStringAttribute("userType", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Employee"
            })
                                      .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.com"
                });
                c.AddStringAttribute("type", new List <string> {
                    "work"
                });
            })
                                      .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.org"
                });
            })
                                      .AddComplexAttribute("name", "urn:ietf:params:scim:schemas:core:2.0:User", (r) =>
            {
                r.AddStringAttribute("familyName", new List <string> {
                    "O'Malley"
                });
            })
                                      .AddComplexAttribute("meta", SCIMConstants.StandardSchemas.CommonSchema.Id, (r) =>
            {
                r.AddDateTimeAttribute("lastModified", new List <DateTime> {
                    DateTime.Parse("2012-05-13T04:42:34Z")
                });
            })
                                      .Build();
            var secondRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                SCIMConstants.StandardSchemas.UserSchema, SCIMConstants.StandardSchemas.CommonSchema
            })
                                       .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Justine"
            })
                                       .AddStringAttribute("title", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "title"
            })
                                       .AddStringAttribute("userType", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Intern"
            })
                                       .AddComplexAttribute("ims", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("type", new List <string> {
                    "xmpp"
                });
                c.AddStringAttribute("value", new List <string> {
                    "foo.com"
                });
            })
                                       .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.be"
                });
            })
                                       .AddComplexAttribute("meta", SCIMConstants.StandardSchemas.CommonSchema.Id, (r) =>
            {
                r.AddDateTimeAttribute("lastModified", new List <DateTime> {
                    DateTime.Parse("2010-05-13T04:42:34Z")
                });
            })
                                       .Build();

            secondRepresentation.LastModified = DateTime.Now;
            var representations = new List <SCIMRepresentation>
            {
                firstRepresentation,
                secondRepresentation
            };

            var otherResult    = ParseAndExecuteFilter(representations.AsQueryable(), "emails co \"example.com\"");
            var firstResult    = ParseAndExecuteFilter(representations.AsQueryable(), "userName eq \"bjensen\"");
            var secondResult   = ParseAndExecuteFilter(representations.AsQueryable(), "name.familyName co \"O'Malley\"");
            var thirdResult    = ParseAndExecuteFilter(representations.AsQueryable(), "userName sw \"J\"");
            var fourthResult   = ParseAndExecuteFilter(representations.AsQueryable(), "title pr");
            var fifthResult    = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified gt \"2011-05-13T04:42:34Z\"");
            var sixResult      = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified ge \"2011-05-13T04:42:34Z\"");
            var sevenResult    = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified lt \"2011-05-13T04:42:34Z\"");
            var eightResult    = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified le \"2011-05-13T04:42:34Z\"");
            var nineResult     = ParseAndExecuteFilter(representations.AsQueryable(), "title pr and userType eq \"Employee\"");
            var tenResult      = ParseAndExecuteFilter(representations.AsQueryable(), "title pr or userType eq \"Intern\"");
            var elevenResult   = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and (emails.value co \"example.org\" or emails.value co \"example.org\")");
            var twelveResult   = ParseAndExecuteFilter(representations.AsQueryable(), "userType ne \"Employee\" and not (emails co \"example.com\" or emails.value co \"example.org\")");
            var thirteenResult = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and (emails.type eq \"work\")");
            var fourteenResult = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and emails[type eq \"work\" and value co \"example.com\"]");
            var fifteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "emails[type eq \"work\" and value co \"example.com\"] or ims[type eq \"xmpp\" and value co \"foo.com\"]");

            Assert.Equal(1, firstResult.Count());
            Assert.Equal(1, secondResult.Count());
            Assert.Equal(1, thirdResult.Count());
            Assert.Equal(2, fourthResult.Count());
            Assert.Equal(1, fifthResult.Count());
            Assert.Equal(1, sixResult.Count());
            Assert.Equal(1, sevenResult.Count());
            Assert.Equal(1, 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());
        }
        public virtual IActionResult Get()
        {
            _logger.LogInformation(Global.StartGetServiceProviderConfig);
            var schema         = SCIMConstants.StandardSchemas.ServiceProvideConfigSchemas;
            var representation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                schema
            })
                                 .AddComplexAttribute("patch", schema.Id, c =>
            {
                c.AddBooleanAttribute("supported", new List <bool> {
                    true
                });
            })
                                 .AddComplexAttribute("bulk", schema.Id, c =>
            {
                c.AddBooleanAttribute("supported", new List <bool> {
                    true
                });
                c.AddIntegerAttribute("maxOperations", new List <int> {
                    _options.MaxOperations
                });
                c.AddIntegerAttribute("maxPayloadSize", new List <int> {
                    _options.MaxPayloadSize
                });
            })
                                 .AddComplexAttribute("filter", schema.Id, c =>
            {
                c.AddBooleanAttribute("supported", new List <bool> {
                    true
                });
                c.AddIntegerAttribute("maxResults", new List <int> {
                    _options.MaxResults
                });
            })
                                 .AddComplexAttribute("changePassword", schema.Id, c =>
            {
                c.AddBooleanAttribute("supported", new List <bool> {
                    false
                });
            })
                                 .AddComplexAttribute("sort", schema.Id, c =>
            {
                c.AddBooleanAttribute("supported", new List <bool> {
                    false
                });
            })
                                 .AddComplexAttribute("etag", schema.Id, c =>
            {
                c.AddBooleanAttribute("supported", new List <bool> {
                    false
                });
            })
                                 .AddComplexAttribute("authenticationSchemes", schema.Id, c =>
            {
                c.AddStringAttribute("name", new List <string> {
                    "OAuth Bearer Token"
                });
                c.AddStringAttribute("description", new List <string> {
                    "Authentication scheme using the OAuth Bearer Token Standard"
                });
                c.AddStringAttribute("specUri", new List <string> {
                    "http://www.rfc-editor.org/info/rfc6750"
                });
                c.AddStringAttribute("type", new List <string> {
                    "oauthbearertoken"
                });
                c.AddBooleanAttribute("primary", new List <bool> {
                    true
                });
            }).Build();
            var location = $"{Request.GetAbsoluteUriWithVirtualPath()}/{SCIMConstants.SCIMEndpoints.ServiceProviderConfig}";

            return(new ContentResult
            {
                StatusCode = (int)HttpStatusCode.OK,
                Content = representation.ToResponse(location, true).ToString(),
                ContentType = "application/scim+json"
            });
        }
Exemple #5
0
        public void When_Parse_And_Execute_Filter()
        {
            var customSchema = SCIMSchemaBuilder.Create("urn:ietf:params:scim:schemas:core:2.0:CustomProperties", "User", SimpleIdServer.Scim.SCIMConstants.SCIMEndpoints.User, "Custom properties", false)
                               .AddDecimalAttribute("age")
                               .AddBinaryAttribute("eidCertificate")
                               .Build();
            var firstRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                SCIMConstants.StandardSchemas.UserSchema, customSchema
            })
                                      .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "bjensen"
            })
                                      .AddBooleanAttribute("active", "urn:ietf:params:scim:schemas:core:2.0:User", new List <bool> {
                true
            })
                                      .AddDecimalAttribute("age", "urn:ietf:params:scim:schemas:core:2.0:CustomProperties", new List <decimal> {
                22
            })
                                      .AddBinaryAttribute("eidCertificate", "urn:ietf:params:scim:schemas:core:2.0:CustomProperties", new List <string> {
                "aGVsbG8="
            })
                                      .AddStringAttribute("title", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "title"
            })
                                      .AddStringAttribute("userType", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Employee"
            })
                                      .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.com"
                });
                c.AddStringAttribute("type", new List <string> {
                    "work"
                });
            })
                                      .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.org"
                });
            })
                                      .AddComplexAttribute("name", "urn:ietf:params:scim:schemas:core:2.0:User", (r) =>
            {
                r.AddStringAttribute("familyName", new List <string> {
                    "O'Malley"
                });
            })
                                      .Build();

            firstRepresentation.LastModified = DateTime.Parse("2012-05-13T04:42:34Z");
            firstRepresentation.Version      = "2";
            var secondRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                SCIMConstants.StandardSchemas.UserSchema
            })
                                       .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Justine"
            })
                                       .AddStringAttribute("title", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "title"
            })
                                       .AddStringAttribute("userType", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Intern"
            })
                                       .AddComplexAttribute("ims", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("type", new List <string> {
                    "xmpp"
                });
                c.AddStringAttribute("value", new List <string> {
                    "foo.com"
                });
            })
                                       .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.be"
                });
            })
                                       .Build();

            secondRepresentation.LastModified = DateTime.Parse("2010-05-13T04:42:34Z");
            var representations = new List <SCIMRepresentation>
            {
                firstRepresentation,
                secondRepresentation
            };

            var otherResult     = ParseAndExecuteFilter(representations.AsQueryable(), "emails co \"example.com\"");
            var firstResult     = ParseAndExecuteFilter(representations.AsQueryable(), "userName eq \"bjensen\"");
            var secondResult    = ParseAndExecuteFilter(representations.AsQueryable(), "name.familyName co \"O'Malley\"");
            var thirdResult     = ParseAndExecuteFilter(representations.AsQueryable(), "userName sw \"J\"");
            var fourthResult    = ParseAndExecuteFilter(representations.AsQueryable(), "title pr");
            var fifthResult     = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified gt \"2011-05-13T04:42:34Z\"");
            var sixResult       = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified ge \"2011-05-13T04:42:34Z\"");
            var sevenResult     = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified lt \"2011-05-13T04:42:34Z\"");
            var eightResult     = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified le \"2011-05-13T04:42:34Z\"");
            var nineResult      = ParseAndExecuteFilter(representations.AsQueryable(), "title pr and userType eq \"Employee\"");
            var tenResult       = ParseAndExecuteFilter(representations.AsQueryable(), "title pr or userType eq \"Intern\"");
            var elevenResult    = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and (emails.value co \"example.org\" or emails.value co \"example.org\")");
            var twelveResult    = ParseAndExecuteFilter(representations.AsQueryable(), "userType ne \"Employee\" and not (emails co \"example.com\" or emails.value co \"example.org\")");
            var thirteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and (emails.type eq \"work\")");
            var fourteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "userType eq \"Employee\" and emails[type eq \"work\" and value co \"example.com\"]");
            var fifteenResult   = ParseAndExecuteFilter(representations.AsQueryable(), "emails[type eq \"work\" and value co \"example.com\"] or ims[type eq \"xmpp\" and value co \"foo.com\"]");
            var sixteenResult   = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified gt \"2011-05-13T04:42:34Z\" and meta.version eq \"2\"");
            var seventeenResult = ParseAndExecuteFilter(representations.AsQueryable(), "meta.lastModified pr");
            var eighteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "age gt 15");
            var nineteenResult  = ParseAndExecuteFilter(representations.AsQueryable(), "eidCertificate eq \"aGVsbG8=\"");

            Assert.Equal(1, firstResult.Count());
            Assert.Equal(1, secondResult.Count());
            Assert.Equal(1, thirdResult.Count());
            Assert.Equal(2, fourthResult.Count());
            Assert.Equal(1, fifthResult.Count());
            Assert.Equal(1, sixResult.Count());
            Assert.Equal(1, sevenResult.Count());
            Assert.Equal(1, 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(2, seventeenResult.Count());
            Assert.Equal(1, eighteenResult.Count());
            Assert.Equal(1, nineteenResult.Count());
        }
Exemple #6
0
        public void When_Parse_And_Execute_OrderBy()
        {
            var firstRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                StandardSchemas.UserSchema, CustomSchema
            })
                                      .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "bjensen"
            })
                                      .AddBooleanAttribute("active", "urn:ietf:params:scim:schemas:core:2.0:User", new List <bool> {
                true
            })
                                      .AddDecimalAttribute("age", "urn:ietf:params:scim:schemas:core:2.0:CustomProperties", new List <decimal> {
                22
            })
                                      .AddBinaryAttribute("eidCertificate", "urn:ietf:params:scim:schemas:core:2.0:CustomProperties", new List <string> {
                "aGVsbG8="
            })
                                      .AddStringAttribute("title", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "title"
            })
                                      .AddStringAttribute("userType", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Employee"
            })
                                      .AddStringAttribute("filePath", "urn:ietf:params:scim:schemas:core:2.0:CustomProperties", new List <string> {
                @"C:\Program Files (x86)\Internet Explorer"
            })
                                      .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.com"
                });
                c.AddStringAttribute("type", new List <string> {
                    "work"
                });
            })
                                      .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.org"
                });
            })
                                      .AddComplexAttribute("name", "urn:ietf:params:scim:schemas:core:2.0:User", (r) =>
            {
                r.AddStringAttribute("familyName", new List <string> {
                    "O'Malley"
                });
            })
                                      .Build();

            firstRepresentation.LastModified = DateTime.Parse("2012-05-13T04:42:34Z");
            firstRepresentation.Version      = 2;
            var secondRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                StandardSchemas.UserSchema
            })
                                       .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Justine"
            })
                                       .AddStringAttribute("title", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "title"
            })
                                       .AddStringAttribute("userType", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "Intern"
            })
                                       .AddComplexAttribute("ims", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("type", new List <string> {
                    "xmpp"
                });
                c.AddStringAttribute("value", new List <string> {
                    "foo.com"
                });
            })
                                       .AddComplexAttribute("emails", "urn:ietf:params:scim:schemas:core:2.0:User", (c) =>
            {
                c.AddStringAttribute("value", new List <string> {
                    "example.be"
                });
            })
                                       .Build();

            secondRepresentation.LastModified = DateTime.Parse("2010-05-13T04:42:34Z");
            var representations = new List <SCIMRepresentation>
            {
                firstRepresentation,
                secondRepresentation
            };

            var reps = representations.OrderBy(s => s.FlatAttributes.Where(a => a.FullPath == StandardSchemas.UserSchema.GetAttribute("userName").Id).FirstOrDefault()).ToList();

            var firstResult  = ParseAndExecutOrderBy(representations.AsQueryable(), "emails.value", SearchSCIMRepresentationOrders.Ascending);
            var secondResult = ParseAndExecutOrderBy(representations.AsQueryable(), "emails.value", SearchSCIMRepresentationOrders.Descending);
            var thirdResult  = ParseAndExecutOrderBy(representations.AsQueryable(), "userName", SearchSCIMRepresentationOrders.Ascending);
            var fourthResult = ParseAndExecutOrderBy(representations.AsQueryable(), "userName", SearchSCIMRepresentationOrders.Descending);
            var firthResult  = ParseAndExecutOrderBy(representations.AsQueryable(), "meta.lastModified", SearchSCIMRepresentationOrders.Ascending);
            var sixResult    = ParseAndExecutOrderBy(representations.AsQueryable(), "meta.lastModified", SearchSCIMRepresentationOrders.Descending);

            Assert.Equal("Justine", firstResult.ElementAt(0).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("bjensen", firstResult.ElementAt(1).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("bjensen", secondResult.ElementAt(0).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("Justine", secondResult.ElementAt(1).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("bjensen", thirdResult.ElementAt(0).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("Justine", thirdResult.ElementAt(1).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("Justine", fourthResult.ElementAt(0).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("bjensen", fourthResult.ElementAt(1).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("Justine", firthResult.ElementAt(0).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("bjensen", firthResult.ElementAt(1).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("bjensen", sixResult.ElementAt(0).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.Equal("Justine", sixResult.ElementAt(1).FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
        }
Exemple #7
0
        public void When_Apply_Patch_To_SCIM_Representation()
        {
            var userSchema = SCIMSchemaBuilder.Create("urn:ietf:params:scim:schemas:core:2.0:User", "User", "User Account")
                             .AddStringAttribute("userName", caseExact: true, uniqueness: SCIMSchemaAttributeUniqueness.SERVER)
                             .AddStringAttribute("firstName")
                             .AddStringAttribute("lastName")
                             .AddStringAttribute("roles", multiValued: true)
                             .AddStringAttribute("familyName")
                             .AddComplexAttribute("adRoles", opt =>
            {
                opt.AddStringAttribute("display");
                opt.AddStringAttribute("value");
            }, multiValued: true)
                             .AddComplexAttribute("attributes", opt =>
            {
                opt.AddStringAttribute("title");
                opt.AddComplexAttribute("subattributes", sopt =>
                {
                    sopt.AddStringAttribute("str");
                    sopt.AddStringAttribute("sstr");
                }, multiValued: true);
                opt.AddComplexAttribute("subtitle", sopt =>
                {
                    sopt.AddStringAttribute("str");
                });
            }, multiValued: true)
                             .AddComplexAttribute("phones", opt =>
            {
                opt.AddStringAttribute("phoneNumber", description: "Phone number");
                opt.AddStringAttribute("type", description: "Type");
            }, multiValued: true, mutability: SCIMSchemaAttributeMutabilities.READWRITE)
                             .Build();
            var userRepresentation = SCIMRepresentationBuilder.Create(new List <SCIMSchema> {
                userSchema
            })
                                     .AddStringAttribute("userName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "john"
            })
                                     .AddStringAttribute("lastName", "urn:ietf:params:scim:schemas:core:2.0:User", new List <string> {
                "lastName"
            })
                                     .AddComplexAttribute("phones", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("phoneNumber", new List <string> {
                    "01"
                });
                b.AddStringAttribute("type", new List <string> {
                    "mobile"
                });
            })
                                     .AddComplexAttribute("phones", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("phoneNumber", new List <string> {
                    "02"
                });
                b.AddStringAttribute("type", new List <string> {
                    "home"
                });
            })
                                     .AddComplexAttribute("attributes", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("title", new List <string> {
                    "title"
                });
                b.AddComplexAttribute("subattributes", (sb) =>
                {
                    sb.AddStringAttribute("str", new List <string> {
                        "1"
                    });
                });
                b.AddComplexAttribute("subtitle", (sb) =>
                {
                    sb.AddStringAttribute("str", new List <string> {
                        "1"
                    });
                });
            })
                                     .AddComplexAttribute("attributes", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("title", new List <string> {
                    "secondTitle"
                });
                b.AddComplexAttribute("subattributes", (sb) =>
                {
                    sb.AddStringAttribute("str", new List <string> {
                        "1"
                    });
                });
            })
                                     .AddComplexAttribute("adRoles", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("display", new List <string> {
                    "display"
                });
                b.AddStringAttribute("value", new List <string> {
                    "user1"
                });
            })
                                     .AddComplexAttribute("adRoles", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("value", new List <string> {
                    "user2"
                });
            })
                                     .AddComplexAttribute("adRoles", "urn:ietf:params:scim:schemas:core:2.0:User", (b) =>
            {
                b.AddStringAttribute("value", new List <string> {
                    "user3"
                });
            })
                                     .Build();

            userRepresentation.ApplyPatches(new List <PatchOperationParameter>
            {
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REPLACE,
                    Path      = "phones.phoneNumber",
                    Value     = "NEWPHONE"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REPLACE,
                    Path      = "userName",
                    Value     = "cassandra"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "phones",
                    Value     = JArray.Parse("[{ phoneNumber : '03', type: 'type1' }, { phoneNumber : '05', type: 'type2' }]")
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REPLACE,
                    Path      = "phones[phoneNumber eq 03].type",
                    Value     = "newType"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REMOVE,
                    Path      = "phones[phoneNumber eq 01]"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REMOVE,
                    Path      = "phones[phoneNumber eq 03].phoneNumber"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "familyName",
                    Value     = "familyName"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "familyName",
                    Value     = "updatedFamilyName"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "roles",
                    Value     = "firstRole"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "roles",
                    Value     = "secondRole"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REPLACE,
                    Value     = JObject.Parse("{ 'firstName' : 'firstName' }")
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REPLACE,
                    Value     = JObject.Parse("{ 'lastName' : 'updatedLastName' }")
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Value     = JObject.Parse("{ 'phoneNumber': '06', 'type': 'mobile' }"),
                    Path      = "phones"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "attributes[title eq title].subattributes",
                    Value     = JObject.Parse("{ 'str' : '2' }")
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "attributes[title eq title].subtitle",
                    Value     = JObject.Parse("{ 'str' : '2' }")
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REPLACE,
                    Path      = "attributes[title eq secondTitle].subattributes",
                    Value     = JObject.Parse("{ 'str' : '3' }")
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.REPLACE,
                    Path      = "adRoles.display",
                    Value     = "NEWUSER"
                },
                new PatchOperationParameter
                {
                    Operation = SCIMPatchOperations.ADD,
                    Path      = "adRoles[value eq user3].display",
                    Value     = "NEWUSER3"
                }
            }, false);

            Assert.True(userRepresentation.FlatAttributes.Count(a => a.SchemaAttribute.FullPath == "adRoles.display" && a.ValueString == "NEWUSER") == 2);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.FullPath == "adRoles.value" && a.ValueString == "user1") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.FullPath == "adRoles.value" && a.ValueString == "user2") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.FullPath == "adRoles.value" && a.ValueString == "user3") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.FullPath == "adRoles.display" && a.ValueString == "NEWUSER3") == true);
            Assert.Equal("cassandra", userRepresentation.FlatAttributes.First(a => a.SchemaAttribute.Name == "userName").ValueString);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "phoneNumber" && a.ValueString == "03") == false);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "phoneNumber" && a.ValueString == "05") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "phoneNumber" && a.ValueString == "01") == false);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "phoneNumber" && a.ValueString == "06") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "familyName" && a.ValueString == "updatedFamilyName") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "roles" && a.ValueString == "firstRole") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "roles" && a.ValueString == "secondRole") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "userName" && a.ValueString == "cassandra") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.Name == "lastName" && a.ValueString == "updatedLastName") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.FullPath == "attributes.subattributes.str" && a.ValueString == "2") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.FullPath == "attributes.subtitle.str" && a.ValueString == "2") == true);
            Assert.True(userRepresentation.FlatAttributes.Any(a => a.SchemaAttribute.FullPath == "attributes.subattributes.str" && a.ValueString == "3") == true);
        }