コード例 #1
0
            internal static List <int> GetAllUserIds(SecurityGroup group)
            {
                var allChildGroups = new List <SecurityGroup>();

                CollectAllChildGroups(group, allChildGroups);

                var userIds = new List <int>();

                foreach (var g in allChildGroups)
                {
                    foreach (var u in g.UserMemberIds)
                    {
                        if (!userIds.Contains(u))
                        {
                            userIds.Add(u);
                        }
                    }
                }
                return(userIds);
            }
コード例 #2
0
            internal void AddUserToGroup(int userId, SecurityGroup parentGroup, Dictionary <int, List <int> > usersTable)
            {
                // collect all relevant groupId from the parent axis
                var allParentGroupIds = GetAllParentGroupIdsInclusive(parentGroup);

                // ensure user
                if (!usersTable.TryGetValue(userId, out var user))
                {
                    user = new List <int>();
                    usersTable.Add(userId, user);
                }

                // complete the user (distinct groupId list) with the relevant groups (allParentGroupIds)
                foreach (var parentGroupId in allParentGroupIds)
                {
                    if (!user.Contains(parentGroupId))
                    {
                        user.Add(parentGroupId);
                    }
                }
            }
コード例 #3
0
            private void CollectAllChildGroups(SecurityGroup group, List <SecurityGroup> allChildGroups)
            {
                // avoid infinite loop because of circular reference
                if (allChildGroups.Contains(group))
                {
                    return;
                }
                // stop if there isn't any parent
                if (group.Groups == null)
                {
                    return;
                }

                // collect
                allChildGroups.Add(group);

                // do recursion
                foreach (var childGroup in group.Groups)
                {
                    CollectAllChildGroups(childGroup, allChildGroups);
                }
            }
コード例 #4
0
            internal void AddGroupToGroup(SecurityGroup group, SecurityGroup parentGroup, Dictionary <int, List <int> > usersTable)
            {
                var allUserIds        = GetAllUserIds(group);
                var allParentGroupIds = GetAllParentGroupIdsInclusive(parentGroup);

                foreach (var userId in allUserIds)
                {
                    if (!usersTable.TryGetValue(userId, out var user))
                    {
                        user = new List <int>();
                        usersTable.Add(userId, user);
                    }

                    foreach (var parentGroupId in allParentGroupIds)
                    {
                        if (!user.Contains(parentGroupId))
                        {
                            user.Add(parentGroupId);
                        }
                    }
                }
            }
コード例 #5
0
            internal void RemoveUserFromGroup(int userId, SecurityGroup parentGroup, Dictionary <int, List <int> > usersTable, IDictionary <int, SecurityGroup> groupsTable)
            {
                var allParents = GetAllParentGroupIdsInclusive(parentGroup);

                RemoveUserFromGroup(userId, allParents, usersTable, groupsTable);
            }
コード例 #6
0
 internal IEnumerable <int> GetAllParentGroupIds(SecurityGroup group)
 {
     return(Flattener.GetAllParentGroupIdsExclusive(group));
 }
コード例 #7
0
 internal IEnumerable <int> GetAllUsersInGroup(SecurityGroup group)
 {
     return(Flattener.GetAllUserIds(group));
 }
コード例 #8
0
ファイル: PermissionQuery.cs プロジェクト: ildika/sn-security
 private static IEnumerable <int> GetDirectOnlyParentGroups(SecurityGroup group)
 {
     return(group.ParentGroups
            .Select(g => g.Id)
            .ToArray());
 }
コード例 #9
0
ファイル: PermissionQuery.cs プロジェクト: ildika/sn-security
 private static IEnumerable <int> GetAllParentGroups(SecurityContext context, SecurityGroup group)
 {
     return(context.Cache.GetAllParentGroupIds(group));
 }