【问题标题】:Invalid credentials connecting to AD/LDS with LdapConnection使用 LdapConnection 连接到 AD/LDS 的凭据无效
【发布时间】:2019-02-12 07:27:42
【问题描述】:

我的机器上运行了一个 AD/LDS 实例,我正在尝试使用 System.DirectoryServices.Protocols.LdapConnection 类连接到它。出于某种原因,每次我调用 Bind() 方法时,它都会抛出一个 LdapException 抱怨无效的凭据。

这是我用来建立连接的代码:

var ldapDirectoryIdentifier = new LdapDirectoryIdentifier(config.Server.Host, config.Server.Port);

var creds = new NetworkCredential(config.Credentials.Username, config.Credentials.Password)
{
    Domain = config.Credentials.
};

ldapConnection = new LdapConnection(ldapDirectoryIdentifier, creds, AuthType.Basic);

if (config.Server.Secure)
{
    cert = new X509Certificate(config.Server.Certificate);
    ldapConnection.SessionOptions.SecureSocketLayer = true;
    ldapConnection.SessionOptions.VerifyServerCertificate = CheckCertificate;
}

ldapConnection.SessionOptions.ProtocolVersion = 3;

try
{
    ldapConnection.Bind();
}
catch (LdapException e)
{
    Log.LogException(e);
    Environment.Exit(e.ErrorCode);
}

配置来自 App.config 文件,如下例所示:

<server host="host" port="389"/>
<credentials username="username" password="password" domain="domain"/>
<usersearch base="ou=test,dc=test,dc=com" filter="(middlename=user)" objectclass="inetorgperson"/>
<devicesearch base="ou=test,dc=test,dc=com" filter="(sn=device)" objectclass="inetorgperson"/>

我已尝试修改凭据部分以使其连接;设置username="DOMAIN\user",有和没有域条目到凭据。我试过弄乱连接字符串,例如&lt;server host="LDAP://host[:389]"/&gt;。它只是说我用来通过 ADSI Edit 和 ldp 连接到实例的凭据无效。

我可以使用 System.DirectoryServices.DirectoryEntry 连接相同的域凭据(本地用户帐户),所以我怀疑 AD/LDS 的 AD 位很挑剔。

有人有什么想法吗?

【问题讨论】:

    标签: c# active-directory ldap


    【解决方案1】:

    它可能在会话选项上。尝试强制认证类型:

    ldapConnection.AuthType = AuthType.Negotiate;
    

    这也可能是您处理证书的方式。尝试以这种方式添加它:

    ldapConnection.ClientCertificates.Add(cert);
    

    【讨论】:

      【解决方案2】:

      我继续检查了可用的 AuthTypes 并将其设置为 Ntlm 是否有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多