在LDAP中通过精确匹配的id搜索用户(SharePoint 2010人员选择器)



我试图在LDAP中搜索用户并在SharePoint PeoplePicker中解析他的名字用户在PeoplePicker中键入用户的idsid,然后点击CheckName代码调用SearchSingleUser(),并键入userid。

示例:我输入'xyz'并点击CheckName然后,下面的方法将使用SamAccountName='xyz'在LDAP中搜索精确匹配的用户。如果找到匹配,那么它应该解析peoplepicker

中的idsid

如果LDAP有域名xyz,但用户类型为xyz,它将不匹配,也不会解析

但是我看到的是名字被解析了一半。

任何线索我错过了什么,只要搜索一个属性的精确匹配?

这是我的代码:

public static string _LDAPSearchDefSingleUser = "(&(objectClass=user)(SamAccountName={0}))";
public static SearchResultCollection SearchSingleUser(string searchPattern)
{
    using (DirectoryEntry root = new DirectoryEntry(ldapPath, username, password))
    {                
        root.AuthenticationType = AuthenticationTypes.None;
        string filter = string.Format(_LDAPSearchDefSingleUser, searchPattern);
        using (DirectorySearcher searcher = new DirectorySearcher(root))
        {                    
            searcher.ReferralChasing = ReferralChasingOption.All;
            searcher.SearchScope = SearchScope.Subtree;
            searcher.Filter = filter;
            searcher.PropertiesToLoad.Add("objectclass");
            searcher.PropertiesToLoad.Add("SamAccountName");
            SearchResultCollection results = searcher.FindAll();
            return results;
        }
    }
}

不确定是否理解您的问题,但我确认以下过滤器:

(&(objectClass=user)(SamAccountName=xyz))

在LDAP搜索中只返回类user的对象,并且属性SamAccountName完全等于'xyz'。

在你的例子中,如果你有多个匹配,那是因为你输入了'*xyz'或'*xyz*'。

为您的信息,我使用完全相同的代码,它的工作原理。

在DirectorySearcher中使用这样的过滤器:"(,(objectClass =用户)(objectCategory =人)(anr = 123 b5),

"anr ="?——比;"anr =";我在另一个userID的例子中发现了这一点。

如果我搜索,我会得到很多对象:一个123B5,但除此之外,我还得到了许多其他用户对象。123年b5_a123年b5123年b56123年b5_t

但是我没有在过滤器中使用*。

与PowerShell或c#相同
这里是我的PS:

$searcher = [adsisearcher]"(&(objectClass=user)(objectCategory=person)(anr=123B5)(Mail=*))"$ADSearchResults = $searcher.FindAll()

现在变得奇怪了:

$searcher = [adsisearcher]"(&(objectClass=user)(objectCategory=person)(SamAccountName=123B5))"$ADSearchResults = $searcher.FindAll()

如果我使用SamAccountName,那么我只得到一个对象。

然后我用ADSIEdit搜索"

最新更新