モジュール java.security.sasl
パッケージ javax.security.sasl

インタフェースSaslClient


public interface SaslClient
SASL認証をクライアントとして実行します。

プロトコル・ライブラリ(LDAPライブラリなど)は、特定のSASLメカニズムによって定義された認証を実行するために、このクラスのインスタンスを取得します。 SaslClientインスタンス・プロセスでメソッドを呼び出すと、チャレンジが処理され、SaslClientによって実装されたSASLメカニズムに従って応答が作成されます。 認証が処理されるときに、SASLクライアントの認証交換の状態が暗号化されます。

次に、LDAPライブラリがどのようにSaslClientを使用するかの例を示します。 まず、SaslClientのインスタンスを取得します。


 SaslClient sc = Sasl.createSaslClient(mechanisms,
     authorizationId, protocol, serverName, props, callbackHandler);
 
これで、クライアントを認証に使用できます。 たとえば、LDAPライブラリは次のようにクライアントを使用できます。

 // Get initial response and send to server
 byte[] response = (sc.hasInitialResponse() ? sc.evaluateChallenge(new byte[0]) :
     null);
 LdapResult res = ldap.sendBindRequest(dn, sc.getName(), response);
 while (!sc.isComplete() &&
     (res.status == SASL_BIND_IN_PROGRESS || res.status == SUCCESS)) {
     response = sc.evaluateChallenge(res.getBytes());
     if (res.status == SUCCESS) {
         // we're done; don't expect to send another BIND
         if (response != null) {
             throw new SaslException(
                 "Protocol error: attempting to send response after completion");
         }
         break;
     }
     res = ldap.sendBindRequest(dn, sc.getName(), response);
 }
 if (sc.isComplete() && res.status == SUCCESS) {
    String qop = (String) sc.getNegotiatedProperty(Sasl.QOP);
    if (qop != null
        && (qop.equalsIgnoreCase("auth-int")
            || qop.equalsIgnoreCase("auth-conf"))) {

      // Use SaslClient.wrap() and SaslClient.unwrap() for future
      // communication with server
      ldap.in = new SecureInputStream(sc, ldap.in);
      ldap.out = new SecureOutputStream(sc, ldap.out);
    }
 }
 
メカニズムに初期応答が含まれている場合、ライブラリは空のチャレンジでevaluateChallenge()を呼び出し、初期応答を取得します。 IMAP4などのプロトコルでは、サーバーへの最初の認証コマンドによる初期応答が含まれていないため、最初にhasInitialResponse()またはevaluateChallenge()を呼び出さないで認証を開始します。 サーバーが認証コマンドに応答すると、初期チャレンジが送信されます。 クライアントが最初にデータを送信するSASLメカニズムでは、サーバーはデータを含まないチャレンジを発行しておかなければいけません。 それによって、空のチャレンジによるevaluateChallenge()への呼出しがクライアントで行われます。

導入されたバージョン:
1.5
関連項目: