在全局目录中验证用户

时间:2009-12-01 23:39:15

标签: c# active-directory windows-authentication

我需要在给定userId,域和密码的情况下验证用户的Windows凭据。我们的Active Directory包含多个域,其中一些我们可以使用以下代码列出:

var domains = System.DirectoryServices.ActiveDirectory.Forest.GetCurrentForest().Domains;

但是,我们还拥有属于林外域的用户。但是,我可以从全球目录(GC)访问它们。下面的代码允许我获取用户标识的目录条目。

System.DirectoryServices.DirectoryEntry globalCatalogDE = new System.DirectoryServices.DirectoryEntry("GC://DC=nsroot,DC=net");
var ds = new System.DirectoryServices.DirectorySearcher(globalCatalogDE);
ds.Filter = "(&(objectClass=user)(sAMAccountName=" + userId + "))";
System.DirectoryServices.DirectoryEntry userDE = ds.FindAll()[0].GetDirectoryEntry();

如何验证属于我无法直接访问但在GC中可供我使用的域的用户?

1 个答案:

答案 0 :(得分:3)

您无法通过查看全局编录对用户进行身份验证,它仅用于搜索(每个域的架构中标有isMemberOfPartialAttributeSet的任何属性都会复制到GC)。

密码不会复制到它;否则你将拥有每个域控制器上整个forrest中所有用户的密码,从安全和复制的角度来看,这将是非常糟糕的。您需要建立与存储用户凭据的域的连接(即您需要访问LDAP端口389或636)。