Example #1
0
        public bool IsInGroup(string userSid, string groupSid)
        {
            var path = _activeDirectoryPathProvider.GetPath();

            try
            {
                return(_activeDirectoryClient.IsInGroup(path, userSid, groupSid));
            }
            catch
            {
                var isLocalUser = userSid.Equals(_userPrincipalProvider.Get().Sid,
                                                 StringComparison.InvariantCultureIgnoreCase);

                // ReSharper disable once InvertIf
                if (isLocalUser)
                {
                    var isInRoleByIdentity = _userPrincipalProvider.IsCurrentUserInRole(groupSid);

                    if (isInRoleByIdentity)
                    {
                        return(true);
                    }
                }

                return(_activeDirectoryClient.IsUserInGroup(userSid, groupSid));
            }
        }
Example #2
0
        public void ShouldGetUserMembershipByDirectoryEntry()
        {
            var path = "WinNT://" + Environment.MachineName;

            var result = _target.IsInGroup(path, "S-1-5-21-1023191730-727829927-3985050192-22364", "S-1-5-21-543419179-2457612372-1216098091-1012");

            result.Should().BeTrue();
        }
        public void AddUser(string groupSid, string userSid)
        {
            var adPath = _activeDirectoryPathProvider.GetPath();

            if (_activeDirectoryClient.IsInGroup(adPath, userSid, groupSid))
            {
                return;
            }

            _activeDirectoryClient.Add(adPath, userSid, groupSid);
        }