使用自定义 UserPrincipal 时,PrincipalSearcher.FindAll 返回不同的结果
鉴于下面的代码,
using (var context = new PrincipalContext(ContextType.Domain, SOME_DOMAIN))
using (UserPrincipal userPrincipal = new UserPrincipal(context) { Enabled = true })
using (PrincipalSearchResult<Principal> results = new PrincipalSearcher(userPrincipal).FindAll())
{
Console.WriteLine(results.Count());
}
using (var context = new PrincipalContext(ContextType.Domain, SOME_DOMAIN))
using (CustomUserPrinciple userPrincipal = new CustomUserPrinciple(context) { Enabled = true })
using (PrincipalSearchResult<Principal> results = new PrincipalSearcher(userPrincipal).FindAll())
{
Console.WriteLine(results.Count());
}
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
public class CustomUserPrinciple : UserPrincipal
{
public CustomUserPrinciple(PrincipalContext context)
: base(context)
{
}
}
我预计计数是相同的,但看起来使用自定义主体的搜索不仅仅返回像第一次搜索那样的用户。结果包括其他 Active Directory 对象类型,例如计算机。
这是设计使然吗?如果是这样,有没有办法可以限制自定义主体搜索仅返回用户?
Given the code below
using (var context = new PrincipalContext(ContextType.Domain, SOME_DOMAIN))
using (UserPrincipal userPrincipal = new UserPrincipal(context) { Enabled = true })
using (PrincipalSearchResult<Principal> results = new PrincipalSearcher(userPrincipal).FindAll())
{
Console.WriteLine(results.Count());
}
using (var context = new PrincipalContext(ContextType.Domain, SOME_DOMAIN))
using (CustomUserPrinciple userPrincipal = new CustomUserPrinciple(context) { Enabled = true })
using (PrincipalSearchResult<Principal> results = new PrincipalSearcher(userPrincipal).FindAll())
{
Console.WriteLine(results.Count());
}
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
public class CustomUserPrinciple : UserPrincipal
{
public CustomUserPrinciple(PrincipalContext context)
: base(context)
{
}
}
I expected the counts to be the same however it looks like the search using the custom principal doesn't return just users like the first search. The results include other active directory object types like computers.
Is this by design and if so, is there a way I can restrict the custom principal search to return just users ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果包括其他活动目录对象类型,如计算机,只是因为如果您使用 ADSIEDIT.MSC(W2K3 支持工具)等工具查看对象,您会发现计算机的 objectClass 也是用户。这是通过以下事实来解释的:在 Active-Directory 的架构中,
computer
类是user
类的子类。它存在一个允许产生差异的属性objectCategory
。您可以这样更改您的课程:
并像这样管理您的查询:
The results include other active directory object types like computers, just because if you look your objects with a tool like ADSIEDIT.MSC (W2K3 support tools) you'll see that the objectClass of a computer is also user. This is explained by the fact that in the Active-Directory's schema the
computer
class is the child of thuser
class. It exists an attributeobjectCategory
that allow to make the difference.You can change your class this way :
And manage you query like this :