コード例 #1
0
        public List <UserInfo> GetDiscoveredUsersByAttributes()
        {
            var users = new List <UserInfo>();

            if (!AllDomainUsers.Any() && !TryLoadLDAPUsers())
            {
                return(users);
            }

            var usersToAdd = AllDomainUsers.Select(ldapObject => ldapObject.ToUserInfo(this, _log));

            users.AddRange(usersToAdd);

            return(users);
        }
コード例 #2
0
        public List <UserInfo> GetDiscoveredUsersByAttributes()
        {
            var users = new List <UserInfo>();

            if (!AllDomainUsers.Any() && !TryLoadLDAPUsers())
            {
                return(users);
            }

            var usersToAdd = AllDomainUsers.Select(CreateUserInfo);

            users.AddRange(usersToAdd);

            return(users);
        }
コード例 #3
0
        private List <LdapObject> FindUsersByPrimaryGroup()
        {
            if (!AllDomainUsers.Any() && !TryLoadLDAPUsers())
            {
                return(null);
            }

            return
                (AllDomainUsers.Where(
                     lu =>
            {
                var primaryGroupId = lu.GetValue(LdapConstants.ADSchemaAttributes.PRIMARY_GROUP_ID) as string;

                return !string.IsNullOrEmpty(primaryGroupId) &&
                primaryGroupId.Equals(PrimaryGroupId, StringComparison.InvariantCultureIgnoreCase);
            })
                 .ToList());
        }
コード例 #4
0
        private List <LdapObject> FindUsersByPrimaryGroup(string sid)
        {
            _log.Debug("LdapUserImporter.FindUsersByPrimaryGroup()");

            if (!AllDomainUsers.Any() && !TryLoadLDAPUsers())
            {
                return(null);
            }

            return
                (AllDomainUsers.Where(
                     lu =>
            {
                var primaryGroupId = lu.GetValue(LdapConstants.ADSchemaAttributes.PRIMARY_GROUP_ID) as string;

                return !string.IsNullOrEmpty(primaryGroupId) &&
                sid.EndsWith(primaryGroupId);
            })
                 .ToList());
        }
コード例 #5
0
        public void SyncUserGroupMembership(UserInfo user)
        {
            if (user == null ||
                !_settings.GroupMembership ||
                AllDomainGroups == null ||
                !AllDomainGroups.Any() && !TryLoadLDAPGroups() ||
                !AllDomainUsers.Any() && !TryLoadLDAPUsers())
            {
                return;
            }

            var domainUser = AllDomainUsers.FirstOrDefault(u => u.Sid.Equals(user.Sid));

            if (domainUser == null)
            {
                return;
            }

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

            foreach (var domainGroup in AllDomainGroups)
            {
                var sid = domainGroup.Sid;

                var members = _ldapHelper.GetGroupAttribute(domainGroup, _settings.GroupAttribute);

                if (members == null)
                {
                    continue;
                }

                foreach (var member in members)
                {
                    var ldapUser = FindUserByMember(member);

                    if (ldapUser == null)
                    {
                        continue;
                    }

                    if (!userAttributeValue.Equals(member, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    var groupInfo = CoreContext.UserManager.GetGroupInfoBySid(sid);

                    if (!Equals(groupInfo, Core.Users.Constants.LostGroupInfo))
                    {
                        CoreContext.UserManager.AddUserIntoGroup(user.ID, groupInfo.ID);
                    }
                }
            }

            var primaryGroup = AllDomainGroups.FirstOrDefault(g => g.Sid.EndsWith("-513"));

            if (primaryGroup == null)
            {
                return;
            }

            var getPrimaryGroup = CoreContext.UserManager.GetGroupInfoBySid(primaryGroup.Sid);

            if (!Equals(getPrimaryGroup, Core.Users.Constants.LostGroupInfo))
            {
                CoreContext.UserManager.AddUserIntoGroup(user.ID, getPrimaryGroup.ID);
            }
        }
コード例 #6
0
        public bool TryLoadLDAPUsers()
        {
            try
            {
                if (!Settings.EnableLdapAuthentication)
                {
                    return(false);
                }

                if (!LdapHelper.IsConnected)
                {
                    LdapHelper.Connect();
                }

                var users = LdapHelper.GetUsers();

                foreach (var user in users)
                {
                    if (string.IsNullOrEmpty(user.Sid))
                    {
                        AllSkipedDomainUsers.Add(user, LdapSettingsStatus.WrongSidAttribute);
                        continue;
                    }

                    if (!CheckLoginAttribute(user, Settings.LoginAttribute))
                    {
                        AllSkipedDomainUsers.Add(user, LdapSettingsStatus.WrongLoginAttribute);
                        continue;
                    }

                    if (!Settings.GroupMembership)
                    {
                        AllDomainUsers.Add(user);
                        continue;
                    }

                    if (!Settings.UserAttribute.Equals(LdapConstants.RfcLDAPAttributes.DN,
                                                       StringComparison.InvariantCultureIgnoreCase) && !CheckUserAttribute(user, Settings.UserAttribute))
                    {
                        AllSkipedDomainUsers.Add(user, LdapSettingsStatus.WrongUserAttribute);
                        continue;
                    }

                    AllDomainUsers.Add(user);
                }

                if (AllDomainUsers.Any())
                {
                    PrimaryGroupIds = AllDomainUsers.Select(u => u.GetValue(LdapConstants.ADSchemaAttributes.PRIMARY_GROUP_ID)).Cast <string>()
                                      .Distinct().ToList();
                }

                return(AllDomainUsers.Any() || !users.Any());
            }
            catch (ArgumentException)
            {
                _log.ErrorFormat("TryLoadLDAPUsers(): Incorrect filter. userFilter = {0}", Settings.UserFilter);
            }

            return(false);
        }