首先,我是 AD / LDAP 等的新手,所以这可能是显而易见的(我希望如此?!)如果我的术语不正确,我深表歉意,请纠正我。
我们有两个域,BUSINESS(作为全球组)和AUTH(作为域本地组),它们之间具有单向信任(AUTH 信任 BUSINESS)。
以下代码适用于位于 BUSINESS 域中的MachineAstring LDAPServer = "BUSINESS"
,当.
但是当在位于 AUTH 域的MachineBstring LDAPServer = "AUTH"
上运行时,它会显示消息2f。未找到用户,因为在步骤 2 中返回的用户是NULL
。如果我更改string LDAPServer = "BUSINESS"
,则在步骤 1 中会引发异常,即找不到域控制器。
请注意,可以成为 BUSINESS 用户的事实LDAPServiceAccount
表明 AUTH 可以看到 BUSINESS。如果我将其更改为,LDAPServiceAccount = "BUSINESS\\NotRealName"
则第 1 步将引发带有无效凭据的异常。这表明它已解析 BUSINESS 域用户对呼叫进行身份验证?如果我改变LDAPServiceAccount = "AUTH\\ValidAccount"
我会得到同样的问题,User == NULL
所以2f。未找到用户。
namespace ConsoleApplication1
{
using System;
using System.DirectoryServices.AccountManagement;
class Program
{
static void Main(string[] args)
{
// Who are we looking for?
string userName = "BUSINESS\\User.Name";
// Where are we looking?
string LDAPServer = "AUTH";
string LDAPServiceAccount = "BUSINESS\\InternalServiceAccountName";
string LDAPServiceAccountPassword = "CorrespondingPassword";
Console.WriteLine("1. Connecting to: " + LDAPServer);
using (PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, LDAPServer, LDAPServiceAccount, LDAPServiceAccountPassword))
{
Console.WriteLine("2. Finding: " + userName);
using (UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, userName))
{
if (user == null)
{
Console.WriteLine("2f. User Not Found!");
Console.ReadKey();
return;
}
Console.WriteLine("3. Getting groups...");
using (var groups = user.GetGroups())
{
Console.WriteLine("4. The groups are:");
foreach (Principal group in groups)
{
Console.WriteLine("\t{0}", group.Name);
}
}
}
}
Console.WriteLine("END.");
}
}
}
我想知道这是否是两个 AD 服务器之间的问题,其中 AUTH 没有与 BUSINESS 一起检查,而是检查用户是否存在于其配置中?我是否需要设置我的 LDAPServiceAccount 用户以获得任何特殊权限?任何指针将不胜感激!