Exemple #1
0
        public List <UserInfo> GetDiscoveredUsersByAttributes(LDAPSupportSettings settings)
        {
            var users = new List <UserInfo>();

            if (AllDomainUsers == null)
            {
                AllDomainUsers = ldapHelper.GetUsersByAttributes(settings);
            }
            domainUsers = new List <LDAPObject>();
            if (AllDomainUsers != null)
            {
                foreach (var user in AllDomainUsers)
                {
                    if (user != null && !user.IsDisabled && IsUserExistsInGroup(user, settings))
                    {
                        domainUsers.Add(user);
                        var userInfo = CreateUserInfo(user, settings);
                        if (CoreContext.UserManager.GetUserBySid("l" + userInfo.Sid).ID == Core.Users.Constants.LostUser.ID &&
                            CoreContext.UserManager.GetUserBySid(userInfo.Sid).ID == Core.Users.Constants.LostUser.ID)
                        {
                            users.Add(userInfo);
                        }
                    }
                }
            }
            return(users);
        }
        public bool TryLoadLDAPUsers()
        {
            try
            {
                if (!_settings.EnableLdapAuthentication)
                {
                    return(false);
                }

                AllDomainUsers = _ldapHelper.GetUsersByAttributes(_settings) ?? new List <LDAPObject>();

                return(true);
            }
            catch (ArgumentException)
            {
                _log.ErrorFormat("Incorrect filter. userFilter = {0}", _settings.UserFilter);
            }

            return(false);
        }
Exemple #3
0
        public override byte CheckSettings(LDAPSupportSettings settings, LDAPUserImporter importer, bool acceptCertificate = false)
        {
            if (!settings.EnableLdapAuthentication)
            {
                return(OPERATION_OK);
            }

            string password = GetPassword(settings.PasswordBytes);

            try
            {
                if (settings.Authentication)
                {
                    CheckCredentials(settings.Login, password, settings.Server, settings.PortNumber, settings.StartTls);
                }
                if (!CheckServerAndPort(settings.Server,
                                        settings.PortNumber, settings.Authentication, settings.Login, password))
                {
                    return(WRONG_SERVER_OR_PORT);
                }
            }
            catch (DirectoryServicesCOMException)
            {
                return(CREDENTIALS_NOT_VALID);
            }
            catch (COMException)
            {
                return(WRONG_SERVER_OR_PORT);
            }

            if (!CheckUserDN(settings.UserDN, settings.Server, settings.PortNumber,
                             settings.Authentication, settings.Login, password, settings.StartTls))
            {
                return(WRONG_USER_DN);
            }
            try
            {
                importer.AllDomainUsers = ldapHelper.GetUsersByAttributes(settings);
            }
            catch (ArgumentException)
            {
                log.ErrorFormat("Incorrect filter. userFilter = {0}", settings.UserFilter);
                return(INCORRECT_LDAP_FILTER);
            }
            if (importer.AllDomainUsers == null || importer.AllDomainUsers.Count == 0)
            {
                log.ErrorFormat("Any user is not found. userDN = {0}", settings.UserDN);
                return(USERS_NOT_FOUND);
            }
            foreach (var user in importer.AllDomainUsers)
            {
                if (!CheckLoginAttribute(user, settings.LoginAttribute))
                {
                    return(WRONG_LOGIN_ATTRIBUTE);
                }
            }
            if (settings.GroupMembership)
            {
                if (!CheckGroupDN(settings.UserDN, settings.Server, settings.PortNumber,
                                  settings.Authentication, settings.Login, password, settings.StartTls))
                {
                    return(WRONG_USER_DN);
                }
                try
                {
                    importer.DomainGroups = ldapHelper.GetGroupsByAttributes(settings);
                }
                catch (ArgumentException)
                {
                    log.ErrorFormat("Incorrect group filter. groupFilter = {0}", settings.GroupFilter);
                    return(INCORRECT_GROUP_LDAP_FILTER);
                }
                if (importer.DomainGroups == null || importer.DomainGroups.Count == 0)
                {
                    return(GROUPS_NOT_FOUND);
                }
                foreach (var group in importer.DomainGroups)
                {
                    if (!CheckGroupAttribute(group, settings.GroupAttribute))
                    {
                        return(WRONG_GROUP_ATTRIBUTE);
                    }
                    if (!CheckGroupNameAttribute(group, settings.GroupNameAttribute))
                    {
                        return(WRONG_GROUP_NAME_ATTRIBUTE);
                    }
                }
                foreach (var user in importer.AllDomainUsers)
                {
                    if (!CheckUserAttribute(user, settings.UserAttribute))
                    {
                        return(WRONG_USER_ATTRIBUTE);
                    }
                }
            }
            return(OPERATION_OK);
        }