1

私は、識別名を使用してユーザーを検証するために、見つかったユーザーに再バインドするいくつかの機能する LDAP コードを持っています。事実上、これは起こっていることです:

            string userDn = @"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";
            string fullPath = @"LDAP://surinam.testsite.ac.uk:636/" + userDn;

            DirectoryEntry authUser = new DirectoryEntry(fullPath, userDn, "mypassword", AuthenticationTypes.None);

            authUser.RefreshCache();

ただし、これにより、DirectoryEntry.Bind() で不明なエラー 80005000 が発生します。

問題は、DN の CN 属性に「+」と「=」が含まれていることにあるのではないかと考えました。したがって、これをエスケープする方法は、\ と文字の 16 進値を使用する必要があることがわかった後、これを試しました。

            string userDn = @"cn=Feat Studentl\2Bumanroleid\3D302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";

ただし、次のエラーが表示されます。

ログインの失敗: 不明なユーザー名または間違ったパスワード

これは、リクエストには満足しているが、何らかの理由でユーザー DN との一致に失敗しているためだと思います。

とにかくこのあたりはありますか?

4

2 に答える 2

1

LDAP サービスを開発した私の経験では、無効な資格情報が原因でログインに失敗する場合は常に、それバインド試行の問題である傾向があります。DirectoryEntry は DN 内のエスケープされた文字を解析しないため、このエラーが発生します...ただし、そもそもそれを行う必要はありません。

あなたのコードでは、AuthenticationTypes を "None" に設定すると、提供している DN に基づいてエントリが単純なバインドを強制的に作成します。パスの一部としてサーバー名を含めているので、代わりに次のように ServerBind 認証タイプを使用してみます。

string LdapPath = ("LDAP://" + ldapUrl + "/" + Domain);

//Build the user and issue the Refresh bind
var dirEntry = new DirectoryEntry
                   {
                       Path = LdapPath,
                       Username = _usernameToVerify,
                       Password = _passwordToVerify,
                       AuthenticationType = AuthenticationTypes.ServerBind
                   };

//This will load any available properties for the user
dirEntry.RefreshCache();

また、セキュア LDAP ポート (636) に対してこの呼び出しを行っているように見えるため、 ServerBind mechansim とともに AuthenticationTypes.SecureSocketsLayer も含めるようにしてください。

AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.SecureSocketsLayer

お役に立てれば!

于 2013-02-19T16:10:35.703 に答える
0

ある顧客向けにカスタマイズされた古い DLL プロジェクトを掘り下げる必要がありました。

私はそれを機能させることができました。エスケープ文字を含む DN がある場合は、これらの低レベルのディレクトリ サービス ルーチンを参照する必要があるようです。(実際には、DN は、DirectorySearcher をセットアップして最初に FindOne を実行することにより、最初の柔軟なユーザー検索によって取得されることに注意してください)

 string userDn = @"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";
 string basicUrl = @"surinam.testsite.ac.uk:636";



  var ldapConnection = new LdapConnection(basicUrl);
  ldapConnection.AuthType = AuthType.Basic;
  LdapSessionOptions options = ldapConnection.SessionOptions;
  options.ProtocolVersion = 3;
  options.SecureSocketLayer = true;

  NetworkCredential credential = new NetworkCredential(userDn, password);                             
  ldapConnection.Credential = credential;

  try
  {
      ldapConnection.Bind();
      Console.WriteLine("bind succeeded ");
  }
  catch (LdapException e)
  {
      if (e.ErrorCode == 49)
      {
           Console.WriteLine("bind failed ");
      }
      else
      {
          Console.WriteLine("unexpected result " + e.ErrorCode);
      }
  }
  catch (DirectoryOperationException e)
  {
      Console.WriteLine("unexpected error " + e.Message);
  }
于 2013-02-20T13:02:31.300 に答える