Пример #1
0
        private PrincipalContext GetPrincipalContext()
        {
            var targetAddress          = this.TargetInfo.GetAddress();
            var fullyQualifiedUsername = this.TargetInfo.credentials.GetFullyQualifiedUsername();

            return(AccManUtils.accManConnect(targetAddress, fullyQualifiedUsername, this.TargetInfo.credentials.GetPassword()));
        }
Пример #2
0
        private IEnumerable <String> GetUserGroupsByUserID(string userSID)
        {
            PrincipalContext principalContext = this.GetPrincipalContext();
            List <Principal> allGroupUsers    = AccManUtils.getGroupsByUserSid(principalContext, userSID);

            var result = new List <String>();

            foreach (Principal groupUser in allGroupUsers)
            {
                result.Add(groupUser.Sid.ToString());
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Gets the groups the user belongs
        /// </summary>
        /// <param name="username">The user name in FQDN format. For SYSTEM accounts do not use FQDN.</param>
        /// <param name="returnType">Defines wether will be returned the group name ou SID.</param>
        /// <returns>A list of group names or group SIDs according with returnType argument.</returns>
        public virtual IEnumerable <String> GetUserGroups(string username, AccountSearchReturnType returnType)
        {
            var address          = this.TargetInfo.GetAddress();
            var credentials      = this.TargetInfo.credentials;
            var principalContext = AccManUtils.accManConnect(address, credentials.GetUserName(), credentials.GetPassword());

            Principal user            = null;
            var       isSystemAccount = !username.Contains("\\");

            if (isSystemAccount)
            {
                var wqlGetUserSID = GetWqlToGetUserDetails(username);
                var wqlResult     = this.WmiProvider.ExecuteWQL(wqlGetUserSID).FirstOrDefault();
                if (wqlResult != null)
                {
                    var userSID = wqlResult.GetFieldValueAsString("SID");
                    user = Principal.FindByIdentity(principalContext, IdentityType.Sid, userSID);
                }
            }
            else
            {
                user = Principal.FindByIdentity(principalContext, IdentityType.SamAccountName, username);
                if (user == null)
                {
                    user = Principal.FindByIdentity(principalContext, IdentityType.Name, username);
                }
            }

            var groups = new List <String>();

            if (user == null)
            {
                return(groups);
            }

            var foundGroups = user.GetGroups();

            if (foundGroups == null)
            {
                return(groups);
            }

            if (returnType.Equals(AccountSearchReturnType.SID))
            {
                return(foundGroups.Select(g => g.Sid.Value));
            }

            return(foundGroups.Select(g => g.Name));
        }
Пример #4
0
        /// <summary>
        /// Gets the groups the user belongs
        /// </summary>
        /// <param name="username">The user name in FQDN format. For SYSTEM accounts do not use FQDN.</param>
        /// <param name="returnType">Defines wether will be returned the group name ou SID.</param>
        /// <returns>A list of group names or group SIDs according with returnType argument.</returns>
        public virtual IEnumerable <String> GetUserGroups(string username, AccountSearchReturnType returnType)
        {
            var address     = this.TargetInfo.GetAddress();
            var credentials = this.TargetInfo.credentials;

            Principal user            = null;
            var       isSystemAccount = !username.Contains("\\");

            if (isSystemAccount)
            {
                return(GetAllGroupsFromUser(username, returnType));
            }
            else
            {
                var principalContext = AccManUtils.accManConnect(address, credentials.GetUserName(), credentials.GetPassword());
                user = Principal.FindByIdentity(principalContext, IdentityType.SamAccountName, username);
                if (user == null)
                {
                    user = Principal.FindByIdentity(principalContext, IdentityType.Name, username);
                }
            }

            var groups = new List <String>();

            if (user == null)
            {
                return(groups);
            }

            var foundGroups = user.GetGroups();

            if (foundGroups == null)
            {
                return(groups);
            }

            if (returnType.Equals(AccountSearchReturnType.SID))
            {
                return(foundGroups.Select(g => g.Sid.Value));
            }

            return(foundGroups.Select(g => g.Name));
        }
Пример #5
0
        private List <String> GetUsersBelongToGroupByGroupID(string groupSID)
        {
            PrincipalContext principalContext = this.GetPrincipalContext();
            var allUsersSIDOfGroup            = AccManUtils.getMembersOfGroupSidSafely(principalContext, groupSID);

            if ((allUsersSIDOfGroup == null) && (allUsersSIDOfGroup.Count == 0))
            {
                throw new GroupSIDNotFoundException(groupSID);
            }

            var result = new List <String>();

            foreach (var userSIDOfGroup in allUsersSIDOfGroup)
            {
                result.Add(userSIDOfGroup);
            }

            return(result);
        }