【发布时间】:2012-06-15 19:15:35
【问题描述】:
我有两个域,MINE 和 THEIRS。 MINE 是我的本地域,并且与 THEIRS 具有单向信任(使用 LDAPS 端口 636),因此 MINE 信任 THEIRS 但 THEIRS 不信任 MINE。我可以将 THEIRS 中的用户添加到 MINE 中的组,并让 THEIR 中的用户登录到 MINE 网络上的机器和应用程序。信任似乎运作正常。
我正在编写一个小的 .Net 应用程序(不是 ASP.Net)来测试 WAN 上的连接性。我们有一个应用程序在 MINE 中没有看到来自 THEIRS 的用户。其他应用程序(例如 SharePoint)运行良好。
我尝试使用带有 System.DirectoryServices.AccountManagement 对象的 ASP.Net 4 选项,如 PrincipalContext、UserPrincipal、GroupPrincipal 等。快速代码 sn-p
PrincipalContext domainContext = GetDomainContext(DomainName, ConnectionPort,
UseSpecifiedCredentials, Credentials);
GroupPrincipal theGroup = GroupPrincipal.FindByIdentity(domainContext,
IdentityType.SamAccountName, GroupName);
PrincipalCollection theUsers = theGroup.Members;
var users = from u in theUsers
select u.Name;
return users.ToArray();
当我直接连接到 MINE 时,一切都很好。问题在于连接到他们的。 LDAPS 流量的单向信任返回错误:
System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.
所以我使用 DirectoryEntry、DirectorySearcher 等切换到 .Net 2 变体。这实际上适用于 THEIRS 域。
List<string> userNames = new List<string>();
string searchString = string.Format("(sAMAccountName={0})", GroupName);
SearchResult result = SearchAD(DomainName, ConnectionPort, searchString);
我可以直接连接到 THEIRS 域,在代码中使用一些模拟。
当我在 MINE 中查询组时,我从 THEIRS 获取用户的 SID,而不是用户帐户。
The following users are a member of testGroup:
CN=S-1-5-21-....,CN=ForeignSecurityPrincipals,DC=MINE,DC=local
CN=S-1-5-21-....,CN=ForeignSecurityPrincipals,DC=MINE,DC=local
我也尝试过模拟,以 THEIRS 的用户身份运行它,但没有运气。
当用户在 MINE 中时,我如何从 THEIRS 获取用户信息?我是否必须使用上述 CN/SID 并查询 THEIRS 域?我在 .Net 4 中缺少什么?
【问题讨论】:
标签: c# c#-4.0 active-directory