Beispiel #1
0
        public async Task <IEnumerable <ScimUser> > QueryUsers(ScimQueryOptions options)
        {
            var users    = _Mapper.Map <IEnumerable <ScimUser2> >(await _UserManager.GetUsers());
            var filtered = users.Where(options.Filter.ToPredicate <ScimUser2>(_scimServerConfiguration)).ToList();

            return(filtered);
        }
Beispiel #2
0
        public Task <IEnumerable <ScimGroup> > QueryGroups(ScimQueryOptions options)
        {
            var groups = _Groups.Values.AsEnumerable();

            if (options.Filter != null)
            {
                groups = groups.Where(options.Filter.ToPredicate <ScimGroup>(_scimServerConfiguration)).ToList();
            }

            // TODO: (DG) sorting
            if (options.SortBy != null)
            {
            }

            if (options.StartIndex > 1)
            {
                groups = groups.Skip(options.StartIndex);
            }

            if (options.Count > 0)
            {
                groups = groups.Take(options.Count);
            }

            return(Task.FromResult(groups));
        }
Beispiel #3
0
        public async Task <IEnumerable <ScimUser> > QueryUsers(ScimQueryOptions options)
        {
            var users = _Users.Values.AsEnumerable();

            if (options.Filter != null)
            {
                users = users.Where(options.Filter.ToPredicate <ScimUser>()).ToList();
            }

            // TODO: (DG) sorting
            if (options.SortBy != null)
            {
            }

            if (options.StartIndex > 1)
            {
                users = users.Skip(options.StartIndex);
            }

            if (options.Count > 0)
            {
                users = users.Take(options.Count);
            }

            return(users);
        }
        public async Task <IActionResult> Get([FromQuery] ScimQueryOptions options)
        {
            try
            {
                var users = await userService.GetUsers();

                AddLocationHeader("users");
                return(Ok(users));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.InnerException.StackTrace));
            }
        }
 private async Task <HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return((await _GroupService.QueryGroups(options))
            .Let(groups => groups.ForEach(group => SetMetaLocation(group, RetrieveGroupRouteName, new { groupId = group.Id })))
            .Let(groups => groups.ForEach(PopulateMemberRef))
            .Bind(
                groups =>
                new ScimDataResponse <ScimListResponse>(
                    new ScimListResponse2(groups)
     {
         StartIndex = options.StartIndex,
         ItemsPerPage = options.Count
     }))
            .ToHttpResponseMessage(Request));
 }
Beispiel #6
0
 private async Task<HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return (await _GroupService.QueryGroups(options))
         .Let(groups => groups.ForEach(group => SetMetaLocation(group, RetrieveGroupRouteName, new { groupId = group.Id })))
         .Let(groups => groups.ForEach(PopulateMemberRef))
         .Bind(
             groups =>
             new ScimDataResponse<ScimListResponse>(
                 new ScimListResponse2(groups)
                 {
                     StartIndex = options.StartIndex,
                     ItemsPerPage = options.Count
                 }))
         .ToHttpResponseMessage(Request);
 }
 private async Task <HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return((await _UserService.QueryUsers(options))
            .Let(users => users.ForEach(user => SetMetaLocation(user, RetrieveUserRouteName, new { userId = user.Id })))
            .Let(users => users.ForEach(PopulateUserGroupRef))
            .Bind(
                users =>
                new ScimDataResponse <ScimListResponse>(
                    new ScimListResponse2(users)
     {
         StartIndex = options.StartIndex,
         ItemsPerPage = options.Count
     }))
            .ToHttpResponseMessage(Request));
 }
        public async Task<IEnumerable<ScimGroup>> QueryGroups(ScimQueryOptions options)
        {
            var groups = _Groups.Values.AsEnumerable();
            if (options.Filter != null)
                groups = groups.Where(options.Filter.ToPredicate<ScimGroup>(_scimServerConfiguration)).ToList();

            // TODO: (DG) sorting
            if (options.SortBy != null)
            {
            }

            if (options.StartIndex > 1)
                groups = groups.Skip(options.StartIndex);

            if (options.Count > 0)
                groups = groups.Take(options.Count);

            return groups;
        }
        public async Task<IEnumerable<ScimUser>> QueryUsers(ScimQueryOptions options)
        {
            var users = _Users.Values.AsEnumerable();
            if (options.Filter != null)
                users = users.Where(options.Filter.ToPredicate<ScimUser>(_scimServerConfiguration)).ToList();
            
            // TODO: (DG) sorting
            if (options.SortBy != null)
            {
            }

            if (options.StartIndex > 1)
                users = users.Skip(options.StartIndex);

            if (options.Count > 0)
                users = users.Take(options.Count);

            return users;
        }
Beispiel #10
0
 private async Task <HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return((await _UserService.QueryUsers(options))
            .Let(users => users.ForEach(user => SetMetaLocation(user, RetrieveUserRouteName, new { userId = user.Id })))
            .Let(users => users.ForEach(user =>
     {
         // materialize enumerable, otherwise it does not work
         var groups = user.Groups?.ToList();
         groups?.ForEach(ug => ug.Ref = GetGroupUri(GroupsController.RetrieveGroupRouteName, ug.Value));
         user.Groups = groups;
     }))
            .Bind(
                users =>
                new ScimDataResponse <ScimListResponse>(
                    new ScimListResponse1(users)
     {
         StartIndex = options.StartIndex,
         ItemsPerPage = options.Count
     }))
            .ToHttpResponseMessage(Request));
 }
Beispiel #11
0
 private async Task<HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return (await _UserService.QueryUsers(options))
         .Let(users => users.ForEach(user => SetMetaLocation(user, RetrieveUserRouteName, new { userId = user.Id })))
         .Let(users => users.ForEach(user =>
         {
             // materialize enumerable, otherwise it does not work
             var groups = user.Groups?.ToList();
             groups?.ForEach(ug => ug.Ref = GetGroupUri(GroupsController.RetrieveGroupRouteName, ug.Value));
             user.Groups = groups;
         }))
         .Bind(
             users => 
             new ScimDataResponse<ScimListResponse>(
                 new ScimListResponse1(users)
                 {
                     StartIndex = options.StartIndex,
                     ItemsPerPage = options.Count
                 }))
         .ToHttpResponseMessage(Request);
 }
 private async Task <HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return((await _GroupService.QueryGroups(options))
            .Let(groups => groups.ForEach(group => SetMetaLocation(group, RetrieveGroupRouteName, new { groupId = group.Id })))
            .Let(groups => groups.ForEach(group =>
     {
         // needed to materialize ienumerable, otherwise it did not work
         var members = group.Members?.ToList();
         members?.ForEach(m =>
                          m.Ref = m.Type == ScimConstants.ResourceTypes.User
                     ? GetUserUri(UsersController.RetrieveUserRouteName, m.Value)
                     : GetGroupUri(RetrieveGroupRouteName, m.Value));
         group.Members = members;
     }))
            .Bind(
                groups =>
                new ScimDataResponse <ScimListResponse>(
                    new ScimListResponse1(groups)
     {
         StartIndex = options.StartIndex,
         ItemsPerPage = options.Count
     }))
            .ToHttpResponseMessage(Request));
 }
Beispiel #13
0
 private async Task<HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return (await _GroupService.QueryGroups(options))
         .Let(groups => groups.ForEach(group => SetMetaLocation(group, RetrieveGroupRouteName, new { groupId = group.Id })))
         .Let(groups => groups.ForEach(group =>
         {
             // needed to materialize ienumerable, otherwise it did not work
             var members = group.Members?.ToList();
             members?.ForEach(m =>
                 m.Ref = m.Type == ScimConstants.ResourceTypes.User
                     ? GetUserUri(UsersController.RetrieveUserRouteName, m.Value)
                     : GetGroupUri(RetrieveGroupRouteName, m.Value));
             group.Members = members;
         }))
         .Bind(
             groups =>
             new ScimDataResponse<ScimListResponse>(
                 new ScimListResponse1(groups)
                 {
                     StartIndex = options.StartIndex,
                     ItemsPerPage = options.Count
                 }))
         .ToHttpResponseMessage(Request);
 }
Beispiel #14
0
 public Task <HttpResponseMessage> PostQuery(ScimQueryOptions queryOptions)
 {
     return(Query(queryOptions));
 }
Beispiel #15
0
        public virtual async Task<IScimResponse<IEnumerable<ScimGroup>>> QueryGroups(ScimQueryOptions options)
        {
            var groups = await _GroupRepository.QueryGroups(options) ?? new List<ScimGroup>();
            groups.ForEach(group =>
            {
                // repository populates meta only if it sets Created and/or LastModified
                if (group.Meta == null)
                {
                    group.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.Group);
                }

                SetResourceVersion(group);
            });

            return new ScimDataResponse<IEnumerable<ScimGroup>>(groups);
        }
Beispiel #16
0
        public virtual async Task<IScimResponse<IEnumerable<ScimUser>>> QueryUsers(ScimQueryOptions options)
        {
            var users = await _UserRepository.QueryUsers(options) ?? new List<ScimUser>();
            users.ForEach(user =>
            {
                // repository populates meta only if it sets Created and/or LastModified
                if (user.Meta == null)
                {
                    user.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.User);
                }

                SetResourceVersion(user);
            });

            return new ScimDataResponse<IEnumerable<ScimUser>>(users);
        }
Beispiel #17
0
 private async Task<HttpResponseMessage> Query(ScimQueryOptions options)
 {
     return (await _UserService.QueryUsers(options))
         .Let(users => users.ForEach(user => SetMetaLocation(user, RetrieveUserRouteName, new {userId = user.Id})))
         .Let(users => users.ForEach(PopulateUserGroupRef))
         .Bind(
             users =>
                 new ScimDataResponse<ScimListResponse>(
                     new ScimListResponse2(users)
                     {
                         StartIndex = options.StartIndex,
                         ItemsPerPage = options.Count
                     }))
         .ToHttpResponseMessage(Request);
 }
Beispiel #18
0
        public virtual async Task <IScimResponse <IEnumerable <ScimGroup> > > QueryGroups(ScimQueryOptions options)
        {
            var groups = await _GroupRepository.QueryGroups(options) ?? new List <ScimGroup>();

            groups.ForEach(group =>
            {
                // repository populates meta only if it sets Created and/or LastModified
                if (group.Meta == null)
                {
                    group.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.Group);
                }

                SetResourceVersion(group);
            });

            return(new ScimDataResponse <IEnumerable <ScimGroup> >(groups));
        }
Beispiel #19
0
 public Task<HttpResponseMessage> PostQuery(ScimQueryOptions queryOptions)
 {
     return Query(queryOptions);
 }
        public static ScimQueryOptions GetScimQueryOptions(this IReadableStringCollection collection, ScimServerConfiguration configuration)
        {
            var queryOptions = new ScimQueryOptions();

            queryOptions.Attributes = collection.GetValues("attributes")
                .ToMaybe()
                .Bind(attributes => new HashSet<string>(attributes.Distinct(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase).ToMaybe())
                .FromMaybe(new HashSet<string>());

            queryOptions.ExcludedAttributes = collection.GetValues("excludedAttributes")
                .ToMaybe()
                .Bind(attributes => new HashSet<string>(attributes.Distinct(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase).ToMaybe())
                .FromMaybe(new HashSet<string>());

            queryOptions.Filter = collection.Get("filter")
                .ToMaybe()
                .Bind(filter =>
                      {
                          var scimFilter = new ScimFilter(configuration.ResourceExtensionSchemas.Keys, filter);

                          return PathFilterExpression.CreateFilterOnly(scimFilter.NormalizedFilterExpression).ToMaybe();
                      })
                .FromMaybe(null);

            queryOptions.SortBy = collection.Get("sortBy");

            queryOptions.SortOrder = collection.Get("sortOrder")
                .ToMaybe()
                .Bind(
                    sortOrder =>
                        (sortOrder.Equals("descending", StringComparison.OrdinalIgnoreCase)
                            ? SortOrder.Descending
                            : SortOrder.Ascending).ToMaybe())
                .FromMaybe(SortOrder.Ascending); // default

            queryOptions.StartIndex = collection.Get("startIndex")
                .ToMaybe()
                .Bind(index =>
                {
                    // The 1-based index of the first query result. A value less than 1 SHALL be interpreted as 1.

                    int indexInt = 1;
                    try { indexInt = Convert.ToInt32(index); } catch {}
                    
                    return (indexInt < 1 ? 1 : indexInt).ToMaybe();
                })
                .FromMaybe(1); // default

            queryOptions.Count = collection.Get("count")
                .ToMaybe()
                .Bind(count =>
                {
                    // Non-negative integer. Specifies the desired maximum number of query 
                    // results per page, e.g., 10. A negative value SHALL be interpreted as 
                    // "0". A value of "0" indicates that no resource indicates that no resource 
                    // except for "totalResults".

                    int countInt = 0;
                    try { countInt = Convert.ToInt32(count); } catch { }

                    return (countInt < 0 ? 0 : countInt).ToMaybe();
                })
                .FromMaybe(configuration.GetFeature<ScimFeatureFilter>(ScimFeatureType.Filter).MaxResults); // default

            return queryOptions;
        }
Beispiel #21
0
        public virtual async Task <IScimResponse <IEnumerable <ScimUser> > > QueryUsers(ScimQueryOptions options)
        {
            var users = await _UserRepository.QueryUsers(options) ?? new List <ScimUser>();

            users.ForEach(user =>
            {
                // repository populates meta only if it sets Created and/or LastModified
                if (user.Meta == null)
                {
                    user.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.User);
                }

                SetResourceVersion(user);
            });

            return(new ScimDataResponse <IEnumerable <ScimUser> >(users));
        }
        public static ScimQueryOptions GetScimQueryOptions(this IReadableStringCollection collection, ScimServerConfiguration configuration)
        {
            var queryOptions = new ScimQueryOptions();

            queryOptions.Attributes = collection.GetValues("attributes")
                                      .ToMaybe()
                                      .Bind(attributes => new HashSet <string>(attributes.Distinct(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase).ToMaybe())
                                      .FromMaybe(new HashSet <string>());

            queryOptions.ExcludedAttributes = collection.GetValues("excludedAttributes")
                                              .ToMaybe()
                                              .Bind(attributes => new HashSet <string>(attributes.Distinct(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase).ToMaybe())
                                              .FromMaybe(new HashSet <string>());

            queryOptions.Filter = collection.Get("filter")
                                  .ToMaybe()
                                  .Bind(filter => new ScimFilter(configuration.ResourceExtensionSchemas.Keys, filter).Paths.MaybeSingle())
                                  .FromMaybe(null);

            queryOptions.SortBy = collection.Get("sortBy");

            queryOptions.SortOrder = collection.Get("sortOrder")
                                     .ToMaybe()
                                     .Bind(
                sortOrder =>
                (sortOrder.Equals("descending", StringComparison.OrdinalIgnoreCase)
                            ? SortOrder.Descending
                            : SortOrder.Ascending).ToMaybe())
                                     .FromMaybe(SortOrder.Ascending); // default

            queryOptions.StartIndex = collection.Get("startIndex")
                                      .ToMaybe()
                                      .Bind(index =>
            {
                // The 1-based index of the first query result. A value less than 1 SHALL be interpreted as 1.

                int indexInt = 1;
                try { indexInt = Convert.ToInt32(index); } catch {}

                return((indexInt < 1 ? 1 : indexInt).ToMaybe());
            })
                                      .FromMaybe(1); // default

            queryOptions.Count = collection.Get("count")
                                 .ToMaybe()
                                 .Bind(count =>
            {
                // Non-negative integer. Specifies the desired maximum number of query
                // results per page, e.g., 10. A negative value SHALL be interpreted as
                // "0". A value of "0" indicates that no resource indicates that no resource
                // except for "totalResults".

                int countInt = 0;
                try { countInt = Convert.ToInt32(count); } catch { }

                return((countInt < 0 ? 0 : countInt).ToMaybe());
            })
                                 .FromMaybe(configuration.GetFeature <ScimFeatureFilter>(ScimFeatureType.Filter).MaxResults); // default

            return(queryOptions);
        }