pGina.Plugin.LocalMachine.LocalAccount.IsUserInGroup C# (CSharp) Method

IsUserInGroup() private method

private IsUserInGroup ( System.DirectoryServices.AccountManagement.UserPrincipal user, GroupInformation groupInfo ) : bool
user System.DirectoryServices.AccountManagement.UserPrincipal
groupInfo pGina.Shared.Types.GroupInformation
return bool
        private bool IsUserInGroup(UserPrincipal user, GroupInformation groupInfo)
        {
            using (GroupPrincipal group = GetGroupPrincipal(groupInfo.Name))
            {
                return IsUserInGroup(user, group);
            }
        }

Same methods

LocalAccount::IsUserInGroup ( System.DirectoryServices.AccountManagement.UserPrincipal user, System.DirectoryServices.AccountManagement.GroupPrincipal group ) : bool
LocalAccount::IsUserInGroup ( string username, string groupname ) : bool

Usage Example

Beispiel #1
0
        /// <summary>
        /// Returns a list of groups of which the user is a member.  It does so in a fashion that
        /// may seem strange since one can call UserPrincipal.GetGroups, but seems to be much faster
        /// in my tests.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private static List <GroupPrincipal> GetGroups(UserPrincipal user)
        {
            List <GroupPrincipal> result = new List <GroupPrincipal>();

            // Get all groups using a PrincipalSearcher and
            GroupPrincipal filter = new GroupPrincipal(m_machinePrincipal);

            using (PrincipalSearcher searcher = new PrincipalSearcher(filter))
            {
                PrincipalSearchResult <Principal> sResult = searcher.FindAll();
                foreach (Principal p in sResult)
                {
                    if (p is GroupPrincipal)
                    {
                        GroupPrincipal gp = (GroupPrincipal)p;
                        if (LocalAccount.IsUserInGroup(user, gp))
                        {
                            result.Add(gp);
                        }
                        else
                        {
                            gp.Dispose();
                        }
                    }
                    else
                    {
                        p.Dispose();
                    }
                }
            }
            return(result);
        }