public async Task <bool> Update(SCIMRepresentation data, CancellationToken token)
        {
            var record = new SCIMRepresentationModel(data, _options.CollectionSchemas);

            if (_session != null)
            {
                await _scimDbContext.SCIMRepresentationLst.ReplaceOneAsync(_session, s => s.Id == data.Id, record);
            }
            else
            {
                await _scimDbContext.SCIMRepresentationLst.ReplaceOneAsync(s => s.Id == data.Id, record);
            }

            return(true);
        }
        public async Task <bool> Add(SCIMRepresentation representation, CancellationToken token)
        {
            var record = new SCIMRepresentationModel(representation, _options.CollectionSchemas);

            if (_session != null)
            {
                await _scimDbContext.SCIMRepresentationLst.InsertOneAsync(_session, record, null, token);
            }
            else
            {
                await _scimDbContext.SCIMRepresentationLst.InsertOneAsync(record, null, token);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static SCIMRepresentation ToDomain(this SCIMRepresentationModel representation)
        {
            var result = new SCIMRepresentation
            {
                Created      = representation.Created,
                ExternalId   = representation.ExternalId,
                LastModified = representation.LastModified,
                Version      = representation.Version,
                ResourceType = representation.ResourceType,
                Id           = representation.Id,
                Schemas      = representation.Schemas.Select(s => ToDomain(s.Schema)).ToList(),
                Attributes   = representation.Attributes.Where(_ => _.Parent == null).Select(s =>
                {
                    return(ToDomain(s));
                }).ToList()
            };

            return(result);
        }
Ejemplo n.º 4
0
        public async Task <bool> Add(SCIMRepresentation data, CancellationToken token)
        {
            var representations = _scimDbContext.SCIMRepresentationLst;
            var record          = new SCIMRepresentationModel
            {
                Created      = data.Created,
                ExternalId   = data.ExternalId,
                Id           = data.Id,
                LastModified = data.LastModified,
                ResourceType = data.ResourceType,
                Version      = data.Version,
                Attributes   = data.Attributes.Select(_ => _.ToModel()).ToList()
            };

            record.SetSchemas(data.Schemas.Select(_ => _.ToModel()).ToList(), _options.CollectionSchemas);
            await representations.InsertOneAsync(record, null, token);

            return(true);
        }
Ejemplo n.º 5
0
        public static SCIMRepresentation ToDomain(this SCIMRepresentationModel representation, IMongoDatabase db)
        {
            var result = new SCIMRepresentation
            {
                Created      = representation.Created,
                ExternalId   = representation.ExternalId,
                LastModified = representation.LastModified,
                Version      = representation.Version,
                ResourceType = representation.ResourceType,
                Id           = representation.Id,
                Schemas      = representation.GetSchemas(db).Select(_ => _.ToDomain()).ToList(),
                Attributes   = representation.Attributes.Select(s =>
                {
                    return(ToDomain(s));
                }).ToList()
            };

            return(result);
        }
        public Task <bool> Add(SCIMRepresentation data, CancellationToken token)
        {
            var record = new SCIMRepresentationModel
            {
                Created      = data.Created,
                ExternalId   = data.ExternalId,
                LastModified = data.LastModified,
                Version      = data.Version,
                ResourceType = data.ResourceType,
                Id           = data.Id,
                Attributes   = data.Attributes.Select(a => a.ToModel(data.Id)).ToList(),
                Schemas      = data.Schemas.Select(s => new SCIMRepresentationSchemaModel
                {
                    SCIMRepresentationId = data.Id,
                    SCIMSchemaId         = s.Id
                }).ToList()
            };

            _scimDbContext.SCIMRepresentationLst.Add(record);
            return(Task.FromResult(true));
        }
        private static SCIMRepresentationModel ToModel(SCIMRepresentation representation)
        {
            var result = new SCIMRepresentationModel
            {
                Id           = representation.Id,
                Created      = representation.Created,
                ExternalId   = representation.ExternalId,
                LastModified = representation.LastModified,
                Version      = representation.Version,
                ResourceType = representation.ResourceType,
                DisplayName  = representation.DisplayName,
                Attributes   = representation.Attributes.Select(a => a.ToModel(representation.Id)).ToList(),
                Schemas      = representation.Schemas.Select(s => new SCIMRepresentationSchemaModel
                {
                    SCIMRepresentationId = representation.Id,
                    SCIMSchemaId         = s.Id
                }).ToList()
            };

            return(result);
        }
        private void Detach(SCIMRepresentationModel representation)
        {
            _scimDbContext.Entry(representation).State = EntityState.Detached;
            var attributes = _scimDbContext.ChangeTracker.Entries().Where(et =>
            {
                var att = et.Entity as SCIMRepresentationAttributeModel;
                if (att == null)
                {
                    return(false);
                }

                return(att.RepresentationId == representation.Id);
            });
            var ids = attributes.Select(_ => ((SCIMRepresentationAttributeModel)_.Entity).Id).ToList();

            foreach (var attribute in attributes)
            {
                _scimDbContext.Entry(attribute.Entity).State = EntityState.Detached;
            }

            var attributeValues = _scimDbContext.ChangeTracker.Entries().Where(et =>
            {
                var att = et.Entity as SCIMRepresentationAttributeValueModel;
                if (att == null)
                {
                    return(false);
                }

                return(ids.Contains(att.SCIMRepresentationAttributeId));
            });

            foreach (var attribute in attributeValues)
            {
                _scimDbContext.Entry(attribute.Entity).State = EntityState.Detached;
            }
        }
Ejemplo n.º 9
0
        public void When_Parse_And_Execute_Filter()
        {
            var firstRepresentation = new SCIMRepresentationModel
            {
                Id           = Guid.NewGuid().ToString(),
                ExternalId   = "externalId",
                Created      = DateTime.UtcNow,
                LastModified = DateTime.UtcNow,
                ResourceType = "user",
                Attributes   = new List <SCIMRepresentationAttributeModel>
                {
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "userName",
                            Type = SCIMSchemaAttributeTypes.STRING
                        },
                        Values = new List <SCIMRepresentationAttributeValueModel>
                        {
                            new SCIMRepresentationAttributeValueModel
                            {
                                Id          = Guid.NewGuid().ToString(),
                                ValueString = "bjensen"
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "name",
                            Type = SCIMSchemaAttributeTypes.COMPLEX
                        },
                        Children = new List <SCIMRepresentationAttributeModel>
                        {
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "familyName",
                                    Type = SCIMSchemaAttributeTypes.STRING
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        ValueString = "O'Malley"
                                    }
                                }
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "title",
                            Type = SCIMSchemaAttributeTypes.STRING
                        },
                        Values = new List <SCIMRepresentationAttributeValueModel>
                        {
                            new SCIMRepresentationAttributeValueModel
                            {
                                Id          = Guid.NewGuid().ToString(),
                                ValueString = "title"
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "userType",
                            Type = SCIMSchemaAttributeTypes.STRING
                        },
                        Values = new List <SCIMRepresentationAttributeValueModel>
                        {
                            new SCIMRepresentationAttributeValueModel
                            {
                                Id          = Guid.NewGuid().ToString(),
                                ValueString = "Employee"
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "emails",
                            Type = SCIMSchemaAttributeTypes.COMPLEX
                        },
                        Children = new List <SCIMRepresentationAttributeModel>
                        {
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "value",
                                    Type = SCIMSchemaAttributeTypes.STRING
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        ValueString = "example.com"
                                    }
                                }
                            },
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "type",
                                    Type = SCIMSchemaAttributeTypes.STRING
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        ValueString = "work"
                                    }
                                }
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "emails",
                            Type = SCIMSchemaAttributeTypes.COMPLEX
                        },
                        Children = new List <SCIMRepresentationAttributeModel>
                        {
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "value",
                                    Type = SCIMSchemaAttributeTypes.STRING
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        ValueString = "example.org"
                                    }
                                }
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "phoneNumbers",
                            Type = SCIMSchemaAttributeTypes.COMPLEX
                        },
                        Children = new List <SCIMRepresentationAttributeModel>
                        {
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "primary",
                                    Type = SCIMSchemaAttributeTypes.BOOLEAN
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id           = Guid.NewGuid().ToString(),
                                        ValueBoolean = true
                                    }
                                }
                            }
                        }
                    }
                }
            };

            firstRepresentation.LastModified = DateTime.Parse("2012-05-13T04:42:34Z");
            firstRepresentation.Version      = "2";
            var secondRepresentation = new SCIMRepresentationModel
            {
                Id           = Guid.NewGuid().ToString(),
                ExternalId   = "externalId",
                Created      = DateTime.UtcNow,
                LastModified = DateTime.UtcNow,
                ResourceType = "user",
                Attributes   = new List <SCIMRepresentationAttributeModel>
                {
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "userName",
                            Type = SCIMSchemaAttributeTypes.STRING
                        },
                        Values = new List <SCIMRepresentationAttributeValueModel>
                        {
                            new SCIMRepresentationAttributeValueModel
                            {
                                Id          = Guid.NewGuid().ToString(),
                                ValueString = "Justine"
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "title",
                            Type = SCIMSchemaAttributeTypes.STRING
                        },
                        Values = new List <SCIMRepresentationAttributeValueModel>
                        {
                            new SCIMRepresentationAttributeValueModel
                            {
                                Id          = Guid.NewGuid().ToString(),
                                ValueString = "title"
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "userType",
                            Type = SCIMSchemaAttributeTypes.STRING
                        },
                        Values = new List <SCIMRepresentationAttributeValueModel>
                        {
                            new SCIMRepresentationAttributeValueModel
                            {
                                Id          = Guid.NewGuid().ToString(),
                                ValueString = "Intern"
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "emails",
                            Type = SCIMSchemaAttributeTypes.COMPLEX
                        },
                        Children = new List <SCIMRepresentationAttributeModel>
                        {
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "value",
                                    Type = SCIMSchemaAttributeTypes.STRING
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        ValueString = "example.be"
                                    }
                                }
                            }
                        }
                    },
                    new SCIMRepresentationAttributeModel
                    {
                        Id = Guid.NewGuid().ToString(),
                        SchemaAttribute = new SCIMSchemaAttributeModel
                        {
                            Name = "ims",
                            Type = SCIMSchemaAttributeTypes.COMPLEX
                        },
                        Children = new List <SCIMRepresentationAttributeModel>
                        {
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "type",
                                    Type = SCIMSchemaAttributeTypes.STRING
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        ValueString = "xmpp"
                                    }
                                }
                            },
                            new SCIMRepresentationAttributeModel
                            {
                                Id = Guid.NewGuid().ToString(),
                                SchemaAttribute = new SCIMSchemaAttributeModel
                                {
                                    Name = "value",
                                    Type = SCIMSchemaAttributeTypes.STRING
                                },
                                Values = new List <SCIMRepresentationAttributeValueModel>
                                {
                                    new SCIMRepresentationAttributeValueModel
                                    {
                                        Id          = Guid.NewGuid().ToString(),
                                        ValueString = "foo.com"
                                    }
                                }
                            }
                        }
                    }
                }
            };

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

            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(), "phoneNumbers[primary eq \"true\"]");

            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());
        }