检查AD中是否存在Sharepoint用户

时间:2011-11-30 06:18:58

标签: sharepoint

如果用户从AD中删除,则该用户仍然存在于sharepoint中。现在我想检查AD中是否存在用户,那么是否有任何共享点对象模型可以执行此操作?

提前致谢。

1 个答案:

答案 0 :(得分:1)

如果用户位于域用户组中,它将收集该用户组下的所有用户,并将列表循环到该用户,以尝试查找当前用户。如果找到用户,则返回true,否则返回false

查看本文Check Whether User Exists in Active Directory,其中包含一些与安全相关的问题以实现此要求。

// Get ad users in the groups. Since MOSS does
                    // not support nested groups
                    // this will always be a collection of AD users
                    // and groups
                    foreach (SPUser user in group.Users)
                    {
                        // Check if this is a Group
                        if (!user.IsDomainGroup)
                        {
                            // Verify if the user name matches the user name in group
                            if (user.LoginName.ToUpper().Equals(upperCaseUserName))
                            {
                                // if a match is confirmed, return from the method.
                                // There is no need to continue
                                userIsInGroup = true;
                                return; 
                            }
                        }
                        else {
                        // If the AD entity is a User Group,
                        // then check for users in that group
                        if (IsUserInADGroup(web, user.LoginName, 
                            username, out reachedMax))
                        {
                            userIsInGroup = true;
                            return;
                        }
                    }

希望这有帮助..