コード例 #1
0
        public void AddUserIntoGroups(UserInfo user, LDAPSupportSettings settings)
        {
            if (user == null || !settings.GroupMembership || DomainGroups == null)
            {
                return;
            }

            var domainUser = FindDomainUser(user.Sid);

            if (domainUser == null)
            {
                return;
            }

            var dn = ADDomain.GetUserAttribute(domainUser, settings.UserAttribute);

            foreach (var domainGroup in DomainGroups)
            {
                var members = ADDomain.GetGroupAttribute(domainGroup, settings.GroupAttribute);
                if (members != null)
                {
                    if (members.Value != null)
                    {
                        foreach (var member in members)
                        {
                            var memberString = member.ToString();
                            if (IsUser(memberString))
                            {
                                if (dn.Equals(memberString, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    var group = CoreContext.GroupManager.GetGroupInfoBySid(domainGroup.Sid.Value);
                                    if (group != Core.Users.Constants.LostGroupInfo)
                                    {
                                        CoreContext.UserManager.AddUserIntoGroup(user.ID, group.ID);
                                    }
                                }
                            }
                            else if (!_cache.Exists(memberString, domainGroup.Sid.Value) && IsGroup(memberString))
                            {
                                _cache.Add(memberString, domainGroup.Sid.Value);
                            }
                        }
                    }
                }
            }
            if (_primaryGroup != null)
            {
                var primaryGroup = CoreContext.GroupManager.GetGroupInfoBySid(_primaryGroup.Sid);
                if (primaryGroup != Core.Users.Constants.LostGroupInfo)
                {
                    CoreContext.UserManager.AddUserIntoGroup(user.ID, primaryGroup.ID);
                }
            }
        }
コード例 #2
0
        public void AddUserIntoGroups(UserInfo user, LDAPSupportSettings settings)
        {
            if (user == null || !settings.GroupMembership || DomainGroups == null)
            {
                return;
            }

            var domainUser = FindDomainUser(user.Sid);

            if (domainUser == null)
            {
                return;
            }

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

            foreach (var domainGroup in DomainGroups)
            {
                string sid     = domainGroup.Sid;
                var    members = ldapHelper.GetGroupAttribute(domainGroup, settings.GroupAttribute);
                if (members != null)
                {
                    foreach (string member in members)
                    {
                        if (IsUser(member, settings.UserAttribute))
                        {
                            if (userAttributeValue.Equals(member, StringComparison.InvariantCultureIgnoreCase))
                            {
                                var group = CoreContext.UserManager.GetGroupInfoBySid(sid);
                                if (group != Core.Users.Constants.LostGroupInfo)
                                {
                                    CoreContext.UserManager.AddUserIntoGroup(user.ID, group.ID);
                                }
                            }
                        }
                        else if (!relationGroupCache.Exists(member, sid) && IsGroup(member, settings.UserAttribute))
                        {
                            relationGroupCache.Add(member, sid);
                        }
                    }
                }
            }
            if (primaryGroup != null)
            {
                var getPrimaryGroup = CoreContext.UserManager.GetGroupInfoBySid(primaryGroup.Sid);
                if (getPrimaryGroup != Core.Users.Constants.LostGroupInfo)
                {
                    CoreContext.UserManager.AddUserIntoGroup(user.ID, getPrimaryGroup.ID);
                }
            }
        }