1

System.DirectoryServices.Protocols.net名前空間 APIを使用して SSL 経由で Active Directory に接続しようとしています

Active Directory に接続するために作成したスニペットを次に示します。

LdapConnection ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("<ipaddress>:<port>"));
ldapConnection.AuthType = AuthType.Basic;

LdapSessionOptions options = ldapConnection.SessionOptions;
options.SecureSocketLayer = true;
options.ProtocolVersion = 3;

X509Certificate cert = new X509Certificate();
cert.Import(@"E:\client.crt");

ldapConnection.ClientCertificates.Add(cert);
ldapConnection.Credential = new NetworkCredential("administrator", "xxxxxxxxxx");

ldapConnection.Bind();
Console.WriteLine("successfully connected");

このスニペットを実行しようとすると、常に LDAP サーバーを使用できないというエラーが発生します。同じものに相当するJAVAを作成しましたが、サーバーに接続できるため、証明書またはアクティブディレクトリ接続に問題はないと思います。同じ IP アドレスとポート 389 を使用して、ssl なしで Active Directory に接続することもできます。

ありがとう

4

1 に答える 1

0
LdapConnection ldapConnection = new LdapConnection(server + ":" + port);
ldapConnection.AuthType = AuthType.Basic;
ldapConnection.Credential = new System.Net.NetworkCredential(username,
                                                                  password);
ldapConnection.SessionOptions.ProtocolVersion = 3;
if (sslEnabled)
{
    ldapConnection.SessionOptions.SecureSocketLayer = sslEnabled;
}

これが私がしたことで、SSL経由でADに接続できます。SSL経由で同じサーバーに接続するJavaプログラムがあると言いました。C# と同じマシンから Java プログラムを実行していますか? そうでない場合、および AD に自己署名証明書がある場合は、その証明書をクライアント マシンにインストールして試してください。

于 2016-02-12T07:40:50.943 に答える