예제 #1
0
        private void AddUserGroups(UserInfo item)
        {
            var groups = item.UserPrincipal.GetAuthorizationGroups();

            if (groups != null)
            {
                // iterate over all groups
                foreach (Principal member in groups)
                {
                    // make sure to add only group principals
                    if (member is GroupPrincipal group)
                    {
                        if (Helpers.IsSystemName(true, group.Name))
                        {
                            continue;
                        }

                        var groupInfo = new GroupInfo
                        {
                            Description    = group.Description ?? group.DisplayName,
                            GroupName      = group.Name,
                            GroupPrincipal = group,
                            //IsDanger = item.IsDanger,
                            IsSelected = false
                        };

                        GroupInfos.Add(groupInfo);
                    }
                }
            }
        }
예제 #2
0
        //private void AddLocalUser(string principal)
        //{
        //    string group, user;

        //    if (principal.Contains("\\"))
        //    {
        //        string[] account = principal.Split('\\');
        //        group = account[0];
        //        user = account[1];
        //    }
        //    else
        //    {
        //        group = string.Empty;
        //        user = principal;
        //    }

        //    var userInfo = new UserInfo(
        //        user,
        //        false,
        //        principal,
        //        user,
        //        group,
        //        Environment.MachineName + ", " + principal,
        //        false
        //    );

        //    if (!UserInfos.Contains(userInfo))
        //    {
        //        UserInfos.Add(userInfo);
        //    }
        //}

        #endregion Users

        #region Groups

        private void AddNestedGroups(RuleInfo item)
        {
            Trace.Assert(item.Principal != null, "No RuleInfo.Pricipal");

            var members = ((GroupPrincipal)item.Principal).GetMembers(); //TODO recursive doesn't work - help required!

            try
            {
                foreach (Principal member in members)
                {
                    if (member is GroupPrincipal group)
                    {
                        if (Helpers.IsSystemName(true, group.Name))
                        {
                            continue;
                        }

                        var groupInfo = new GroupInfo
                        {
                            Description    = group.Description ?? group.DisplayName ?? group.SamAccountName,
                            GroupName      = group.Name,
                            GroupPrincipal = group,
                            //IsDanger = item.IsDanger,
                            IsSelected = false
                        };

                        if (!GroupInfos.Contains(groupInfo))
                        {
                            GroupInfos.Add(groupInfo);
                        }
                    }
                }
            }
            catch { } // No network
        }