2.2. Hot Rod エンドポイント認証メカニズム
Data Grid は、Hot Rod コネクターを使用して以下の SASL 認証メカニズムをサポートします。
| 認証メカニズム | 説明 | 関連する詳細 |
|---|---|---|
|
|
プレーンテキスト形式の認証情報を使用します。 |
|
|
|
ハッシュアルゴリズムとナンス値を使用します。ホットロッドコネクターは、強度の順に、 |
|
|
|
ハッシュアルゴリズムとナンス値に加えてソルト値を使用します。ホットロッドコネクターは、 |
|
|
|
Kerberos チケットを使用し、Kerberos ドメインコントローラーが必要です。対応する |
|
|
|
Kerberos チケットを使用し、Kerberos ドメインコントローラーが必要です。対応する |
|
|
| クライアント証明書を使用します。 |
|
|
|
OAuth トークンを使用し、 |
|
2.2.1. Hot Rod クライアントの認証メカニズムの設定 リンクのコピーリンクがクリップボードにコピーされました!
Data Grid Server は、さまざまなメカニズムを使用して Hot Rod クライアント接続を認証します。
手順
-
AuthenticationConfigurationBuilderクラスのsaslMechanism()メソッド、またはinfinispan.client.hotrod.sasl_mechanismプロパティーを使用して認証メカニズムを指定します。
SCRAM
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("SCRAM-SHA-512")
.username("myuser")
.password("qwer1234!");
DIGEST
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("DIGEST-MD5")
.username("myuser")
.password("qwer1234!");
PLAIN
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("PLAIN")
.username("myuser")
.password("qwer1234!");
OAUTHBEARER
String token = "..."; // Obtain the token from your OAuth2 provider
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("OAUTHBEARER")
.token(token);
EXTERNAL
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder
.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.ssl()
// TrustStore stores trusted CA certificates for the server.
.trustStoreFileName("/path/to/truststore")
.trustStorePassword("truststorepassword".toCharArray())
.trustStoreType("PCKS12")
// KeyStore stores valid client certificates.
.keyStoreFileName("/path/to/keystore")
.keyStorePassword("keystorepassword".toCharArray())
.keyStoreType("PCKS12")
.authentication()
.saslMechanism("EXTERNAL");
remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
RemoteCache<String, String> cache = remoteCacheManager.getCache("secured");
GSSAPI
LoginContext lc = new LoginContext("GssExample", new BasicCallbackHandler("krb_user", "krb_password".toCharArray()));
lc.login();
Subject clientSubject = lc.getSubject();
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("GSSAPI")
.clientSubject(clientSubject)
.callbackHandler(new BasicCallbackHandler());
基本的なコールバックハンドラー
BasicCallbackHandler は、GSSAPI の例に示されているように、次のコールバックを呼び出します。
-
NameCallbackおよびPasswordCallbackは、クライアントサブジェクトを構築します。 -
AuthorizeCallbackは、SASL 認証中に呼び出されます。
トークンコールバックハンドラーを備えた OAUTHBEARER
次の例のように、TokenCallbackHandler を使用して、OAuth2 トークンが期限切れになる前に更新します。
String token = "..."; // Obtain the token from your OAuth2 provider
TokenCallbackHandler tokenHandler = new TokenCallbackHandler(token);
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.authentication()
.saslMechanism("OAUTHBEARER")
.callbackHandler(tokenHandler);
remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
RemoteCache<String, String> cache = remoteCacheManager.getCache("secured");
// Refresh the token
tokenHandler.setToken("newToken");
カスタムの CallbackHandler
Hot Rod クライアントは、SASL メカニズムに認証情報を渡すためにデフォルトの CallbackHandler を設定します。次の例のように、カスタムの CallbackHandler を提供しないといけない場合があります。
public class MyCallbackHandler implements CallbackHandler {
final private String username;
final private char[] password;
final private String realm;
public MyCallbackHandler(String username, String realm, char[] password) {
this.username = username;
this.password = password;
this.realm = realm;
}
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(username);
} else if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(password);
} else if (callback instanceof AuthorizeCallback) {
AuthorizeCallback authorizeCallback = (AuthorizeCallback) callback;
authorizeCallback.setAuthorized(authorizeCallback.getAuthenticationID().equals(
authorizeCallback.getAuthorizationID()));
} else if (callback instanceof RealmCallback) {
RealmCallback realmCallback = (RealmCallback) callback;
realmCallback.setText(realm);
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
}
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.addServer()
.host("127.0.0.1")
.port(11222)
.security().authentication()
.serverName("myhotrodserver")
.saslMechanism("DIGEST-MD5")
.callbackHandler(new MyCallbackHandler("myuser","default","qwer1234!".toCharArray()));
カスタムの CallbackHandler は、使用する認証メカニズムに固有のコールバックを処理する必要があります。ただし、考えられる各コールバックタイプの例を提供することは、このドキュメントの範囲を超えています。
2.2.2. GSSAPI ログインコンテキストの作成 リンクのコピーリンクがクリップボードにコピーされました!
GSSAPI メカニズムを使用するには、LoginContextを作成して、Hot Rod クライアント Ticket Granting Ticket (TGT) を取得できるようにする必要があります。
手順
ログイン設定ファイルでログインモジュールを定義します。
gss.conf
GssExample { com.sun.security.auth.module.Krb5LoginModule required client=TRUE; };IBM JDK の場合:
gss-ibm.conf
GssExample { com.ibm.security.auth.module.Krb5LoginModule required client=TRUE; };次のシステムプロパティーを設定します。
java.security.auth.login.config=gss.conf java.security.krb5.conf=/etc/krb5.conf注記krb5.confは、KDC の場所を提供します。kinitコマンドを使用して、Kerberos で認証し、krb5.confを確認します。