예제 #1
0
        private async Task ApplyMembership(string csentryDN, string groupid, IList <string> members, IList <string> owners)
        {
            if (members.Count > 0)
            {
                logger.Trace($"{csentryDN}: Adding {members.Count} members");
                await GraphHelperGroups.AddGroupMembers(this.client, groupid, members, true, this.token);
            }

            if (owners.Count > 0)
            {
                logger.Trace($"{csentryDN}: Adding {owners.Count} owners");
                await GraphHelperGroups.AddGroupOwners(this.client, groupid, owners, true, this.token);
            }
        }
예제 #2
0
        public static async Task UpdateGroupOwners(GraphServiceClient client, string groupid, IList <string> adds, IList <string> deletes, bool ignoreMemberExists, bool ignoreNotFound, CancellationToken token)
        {
            // If we try to delete the last owner on a channel, the operation will fail. If we are swapping out the full set of owners (eg an add/delete of 100 owners), this will never succeed if we do a 'delete' operation first.
            // If we do an 'add' operation first, and the channel already has the maximum number of owners, the call will fail.
            // So the order of events should be to
            //    1) Process all membership removals except for one owner (100-99 = 1 owner)
            //    2) Process all membership adds except for one owner (1 + 99 = 100 owners)
            //    3) Remove the final owner (100 - 1 = 99 owners)
            //    4) Add the final owner (99 + 1 = 100 owners)

            string lastOwnerToRemove = null;

            if (deletes.Count > 0)
            {
                if (adds.Count > 0)
                {
                    // We only need to deal with the above condition if we are processing deletes and adds at the same time

                    lastOwnerToRemove = deletes[0];
                    deletes.RemoveAt(0);
                }

                await GraphHelperGroups.RemoveGroupOwners(client, groupid, deletes, true, token);
            }

            string lastOwnerToAdd = null;

            if (adds.Count > 0)
            {
                if (deletes.Count > 0)
                {
                    // We only need to deal with the above condition if we are processing deletes and adds at the same time

                    lastOwnerToAdd = adds[0];
                    adds.RemoveAt(0);
                }

                await GraphHelperGroups.AddGroupOwners(client, groupid, adds, true, token);
            }

            if (lastOwnerToRemove != null)
            {
                await GraphHelperGroups.RemoveGroupOwners(client, groupid, new List <string>() { lastOwnerToRemove }, ignoreNotFound, token);
            }

            if (lastOwnerToAdd != null)
            {
                await GraphHelperGroups.AddGroupOwners(client, groupid, new List <string>() { lastOwnerToAdd }, ignoreMemberExists, token);
            }
        }
        private async Task ProcessDeferredMembership(IList <string> deferredMembers, Group result, IList <string> deferredOwners, string csentryDN)
        {
            bool success = false;

            while (!success)
            {
                if (deferredMembers.Count > 0)
                {
                    logger.Trace($"{csentryDN}: Adding {deferredMembers.Count} deferred members");
                    await GraphHelperGroups.AddGroupMembers(this.client, result.Id, deferredMembers, true, this.token);
                }

                if (deferredOwners.Count > 0)
                {
                    logger.Trace($"{csentryDN}: Adding {deferredOwners.Count} deferred owners");
                    await GraphHelperGroups.AddGroupOwners(this.client, result.Id, deferredOwners, true, this.token);
                }

                success = true;
            }
        }
        private async Task PutAttributeChangeMembers(CSEntryChange c, AttributeChange change)
        {
            IList <string> valueDeletes = change.GetValueDeletes <string>();
            IList <string> valueAdds    = change.GetValueAdds <string>();

            if (change.ModificationType == AttributeModificationType.Delete)
            {
                if (change.Name == "member")
                {
                    List <DirectoryObject> result = await GraphHelperGroups.GetGroupMembers(this.client, c.DN, this.token);

                    valueDeletes = result.Where(u => !this.userFilter.ShouldExclude(u.Id, this.token)).Select(t => t.Id).ToList();
                }
                else
                {
                    List <DirectoryObject> result = await GraphHelperGroups.GetGroupOwners(this.client, c.DN, this.token);

                    valueDeletes = result.Where(u => !this.userFilter.ShouldExclude(u.Id, this.token)).Select(t => t.Id).ToList();
                }
            }

            if (change.Name == "member")
            {
                await GraphHelperGroups.AddGroupMembers(this.client, c.DN, valueAdds, true, this.token);

                await GraphHelperGroups.RemoveGroupMembers(this.client, c.DN, valueDeletes, true, this.token);

                logger.Info($"Membership modification for group {c.DN} completed. Members added: {valueAdds.Count}, members removed: {valueDeletes.Count}");
            }
            else
            {
                await GraphHelperGroups.AddGroupOwners(this.client, c.DN, valueAdds, true, this.token);

                await GraphHelperGroups.RemoveGroupOwners(this.client, c.DN, valueDeletes, true, this.token);

                logger.Info($"Owner modification for group {c.DN} completed. Owners added: {valueAdds.Count}, owners removed: {valueDeletes.Count}");
            }
        }