WSS SPI を使用する場合は、ユーザー名とパスワードを LTPA トークン生成プログラム LTPAGenerateLoginModule に動的に渡すことができます。
ただし、ポリシー・セットとバインディングを使用する必要がある場合、標準構成ではこの操作ができません。これは、コールバック・ハンドラーと、コールバック・ハンドラー内のユーザー名およびパスワードがいずれも固定値であるためです。カスタム JAAS ログイン・モジュールを使用している場合、ポリシー・セットとバインディングを使用して、動的 Kerberos トークンを作成できます。
始める前に
カスタム JAAS ログイン・モジュールを作成するか、クライアントの要求コンテキストに UsernameToken を追加する場合、LTPA トークンの作成時に LTPA トークン生成プログラムによって使用されるユーザー名とパスワードをカスタマイズできます。また、LTPA トークン生成プログラムで使用するトークン・バイトを直接設定することで、トークンをカスタマイズすることも可能です。トークン・バイトの設定は、インバウンド要求の HTTP ヘッダーから LTPA トークンを取得してアウトバウンド SOAP メッセージのセキュリティー・ヘッダーに配置するためのコードをアプリケーション開発者が作成する際に便利です。
このタスクについて
GenericSecurityTokenFactory は、LTPAGenerateLoginModule が生成する LTPA トークンをカスタマイズする際にこのモジュールで使用可能なトークンを作成するためにユーザーが使用できる SPI を提供します。これらの SPI によって、動的ユーザー名とパスワードの使用やトークン・バイトの直接設定が可能になります。これらはコールバック・ハンドラーによって提供されない機能です。
以下の手順では、スタックされた JAAS ログイン・モジュール・メソッドを使用して、ユーザー名とパスワード、またはトークン・バイトをカスタマイズする方法を示します。この手順を完了すると、新規に作成したトークンをクライアントの要求コンテキストに配置することもできます。クライアントの要求コンテキストにトークンを配置する方法について詳しくは、com.ibm.wsspi.wssecurity.core.Constants
Javadoc にある以下の定数を参照してください。
- com.ibm.wsspi.wssecurity.token.tokenHolder
- com.ibm.wsspi.wssecurity.token.enableCaptureTokenContext
手順
- 動的トークンを作成します。
以下のサブステップのいずれか 1 つを実行します。
- ユーザー名とパスワードをカスタマイズするには、シンプル UsernameToken を作成します。
import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
...
GenericSecurityTokenFactory gstFactory = GenericSecurityTokenFactory.getInstance();
UsernameToken myUnt = gstFactory.getSimpleUsernameToken("myUsername", "myPassword".toCharArray());
- トークン・バイトをカスタマイズするには、シンプル BinarySecurityToken を作成します。
import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
import com.ibm.websphere.wssecurity.wssapi.token.BinarySecurityToken;
import com.ibm.websphere.wssecurity.wssapi.WSSUtilFactory;
...
GenericSecurityTokenFactory gstFactory = GenericSecurityTokenFactory.getInstance();
WSSUtilFactory utilFactory = WSSUtilFactory.getInstance();
//callbackHandler is obtained from the initialize method in the Login Module
Map reqHeaders = utilFactory.getHTTPRequestHeaders(callbackHandler);
//getLtpaHeaderBytes is a method written by you to find the header that
//has the LTPA token in it in the header list, then return the encoded
//bytes out of the header.
String encodedBytes = getLtpaHeaderBytes(reqHeaders);
byte [] decodedBytes = utilFactory.decode(encodedBytes);
BinarySecurityToken bst = factory.getSimpleBinarySecurityToken(com.ibm.websphere.wssecurity.wssapi.token.LTPAv2Token, decodedBytes);
- JAAS ログイン・モジュールを作成します。
package test.tokens;
import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
import com.ibm.websphere.wssecurity.wssapi.token.BinarySecurityToken;
public class MyUntCustomLoginModule implements LoginModule {
//For the sake of readability, this login module does not
//protect against all NPE's
private Map _sharedState;
private Map _options;
private CallbackHandler _handler;
public void initialize(Subject subject, CallbackHandler callbackHandler,
Map<String, ?> sharedState, Map<String, ?> options) {
this._handler = callbackHandler;
this._sharedState = sharedState;
this._options = options;
}
public boolean login() throws LoginException {
GenericSecurityTokenFactory factory = null;
try {
factory = GenericSecurityTokenFactory.getInstance();
} catch (Exception e) {
throw new LoginException(e.toString());
}
//code to create the BinarySecurityToken can be used
//here instead of the simple UsernameToken
UsernameToken unt = factory.getSimpleUsernameToken("myUsername", "myPassword".toCharArray());
factory.putGeneratorTokenToSharedState(this._sharedState, unt);
return true;
}
//implement the rest of the methods required by the
//LoginModule interface
}
- 新規 JAAS ログイン構成を作成します。
- 管理コンソールで、「セキュリティー」->「グローバル・セキュリティー」を選択します。
- 「認証」の下で、「Java 認証・承認サービス」を選択します。
- 「システム・ログイン」を選択します。
- 最初に、カスタム・モジュールを使用してジェネレーターを作成します。
- 「新規」をクリックし、Alias = test.generate.ltpa を指定します。
- 「新規」をクリックし、Module class name = test.tokens.MyUntCustomLoginModule と指定します。
- 「ログイン・モジュール・プロキシーを使用」を選択します。
- 「OK」をクリックします。
- 「新規」をクリックし、com.ibm.ws.wssecurity.wssapi.token.impl.LTPAGenerateLoginModule を選択します。
- 「OK」をクリックします。
- 「JAAS - システム・ログイン」をクリックします。
- 新しい JAAS 構成を使用するよう LTPA トークン生成プログラムを構成します。
- 変更するバインディング構成を開きます。
管理コンソールで、「WS-Security」
>「認証と保護」を選択します。
- 認証トークンの下で、変更するアウトバウンド LTPA トークンを選択します。
- 「JAAS login = test.generate.ltpa」を選択します。
- 「保存」をクリックします。
- アプリケーション・サーバーを再始動して JAAS 構成の変更を適用します。
- サービスをテストします。