public bool IsUserExistsInGroups(UserInfo ldapUser)
        {
            try
            {
                if (!_settings.GroupMembership)
                {
                    return(false);
                }

                if (ldapUser == null ||
                    Equals(ldapUser, Core.Users.Constants.LostUser) ||
                    string.IsNullOrEmpty(ldapUser.Sid))
                {
                    return(false);
                }

                if (!AllDomainGroups.Any() && !TryLoadLDAPGroups())
                {
                    return(false);
                }

                var domainUser = _ldapHelper.GetUserBySid(_settings, ldapUser.Sid);

                if (domainUser == null)
                {
                    return(false);
                }

                var distinguishedName = _ldapHelper.GetUserAttribute(domainUser, _settings.UserAttribute);

                foreach (var domainGroup in AllDomainGroups)
                {
                    if (_ldapHelper.UserExistsInGroup(_settings, domainGroup, distinguishedName, _settings.GroupAttribute))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ldapUser != null)
                {
                    _log.ErrorFormat("IsUserExistInGroups(login: '******' sid: '{1}') error {2}", ldapUser.UserName, ldapUser.Sid, ex);
                }
            }

            return(false);
        }
Esempio n. 2
0
        private bool IsUserExistsInGroup(LDAPObject domainUser, LDAPSupportSettings settings)
        {
            if (!settings.GroupMembership || DomainGroups == null || DomainGroups.Count == 0 || primaryGroup != null)
            {
                return(true);
            }

            var distinguishedName = ldapHelper.GetUserAttribute(domainUser, settings.UserAttribute);

            foreach (var domainGroup in DomainGroups)
            {
                if (ldapHelper.UserExistsInGroup(domainGroup, distinguishedName, settings.GroupAttribute))
                {
                    return(true);
                }
            }

            return(false);
        }