我的机器上运行着一个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"/>我尝试修改credentials部分以使其连接;设置username="DOMAIN\user",并将域条目设置为credentials。我尝试过处理连接字符串,例如<server host="LDAP://host[:389]"/>。它只是说我用来通过ADSI Edit和ldp连接到实例的凭据是无效的。
我可以使用System.DirectoryServices.DirectoryEntry使用相同的域凭据(本地用户帐户)进行连接,所以我怀疑这是AD/LDS的AD位挑剔。
有人有什么想法吗?
发布于 2019-02-12 18:16:31
我继续并仔细检查了可用的AuthTypes,并将其设置为Ntlm works。
发布于 2019-02-12 16:05:23
它可能在会话选项上。尝试强制身份验证类型:
ldapConnection.AuthType = AuthType.Negotiate;这也可能是您处理证书的方式。尝试这样添加:
ldapConnection.ClientCertificates.Add(cert);https://stackoverflow.com/questions/54644821
复制相似问题