デフォルトの伝搬トークンは、使用するアプリケーションおよびセキュリティー・インフラストラクチャーの 実行スレッドに配置されています。WebSphere Application Server はこのデフォルトの伝搬トークンをダウンストリームに伝搬し、 トークンは各ホップで呼び出しを行なうスレッドにとどまります。
データは、伝搬トークンを行う任意のリソースのコンテナーから選択可能です。 伝搬が行われるためには、要求が送られる各サーバーで伝搬機能を使用可能にしておく必要があることに留意してください。 ご使用の環境で伝搬を行いたいすべてのセルについて、 セキュリティー属性の伝搬が使用可能になっていることを確認してください。
PropagationToken 属性にアクセスするためのアプリケーション・プログラミング・インターフェース (API) を有する WSSecurityHelper クラスがあります。 このトピックでは使用法のシナリオを示し、実例を挙げます。 伝搬トークンと作業域フィーチャーの間には、 密接な関係があります。これらのフィーチャー間の主な相違点は、 伝搬トークンに属性を追加した後は、その属性を変更できない点にあります。 セキュリティー・ランタイムが監査可能な情報を追加し、 呼び出しが行われている間、その情報を保持できるようにするため、 これらの属性を変更することはできません。 特定のキーに属性を追加するときはいつでも、 その属性を格納するための ArrayList オブジェクトが保存されます。 同じキーを使用して任意の新規属性を追加すると、 その ArrayList オブジェクトに追加されます。getAttributes を呼び出すと、 ArrayList オブジェクトはストリング配列に変換され、その順序は保持されます。ストリング配列の最初のエレメントは、 その特定キーに追加された最初の属性です。
デフォルトの伝搬トークンでは、 トークンに加えられた任意のデータ変更を記録する変更フラグが立てられます。 これらの変更が追跡されることによって、 WebSphere Application Server は認証情報をどの時点でダウンストリームに再送すべきかを認識でき、 ダウンストリーム・サーバーがその変更を入手できます。 通常は Common Secure Interoperability バージョン 2 (CSIv2) が認証済みクライアント・サーバー間のセッションを維持します。 伝搬トークンが変更されると、新しいセッションが生成され、その結果新しい認証が起こります。 メソッド中の伝搬トークンを頻繁に変更することは、 ダウンストリーム呼び出しが頻繁に行われる原因となります。 下流で多くの呼び出しが行われる前にトークンを変更する場合、または下流 の各呼び出しの間にトークンを変更する場合、セキュリティーのパフォーマンスに影響が及びます。
String[] server_list = null;
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try {
// Gets the server_list string array
server_list = com.ibm.websphere.security.WSSecurityHelper.getServerList();
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
if (server_list != null)
{
// print out each server in the list, server_list[0] is the first server
for (int i=0; i<server_list.length; i++)
{
System.out.println("Server[" + i + "] = " + server_list[i]);
}
}
}
次のコード・サンプルで、getCallerList API の使用方法を示します。
String[] caller_list = null;
// If security is disabled on this application server, do not check the caller list
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try {
// Gets the caller_list string array
caller_list = com.ibm.websphere.security.WSSecurityHelper.getCallerList();
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
if (caller_list != null)
{
// Prints out each caller in the list, caller_list[0] is the first caller
for (int i=0; i<caller_list.length;i++)
{
System.out.println("Caller[" + i + "] = " + caller_list[i]);
}
}
}
リストの各呼び出し元のフォーマットは、cell:node_name:server_name:realm:port_number/securityName です。 例えば、出力は次のようになります。myManager:node1:server1:ldap.austin.ibm.com:389/jsmith
String first_caller = null;
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try {
// Gets the first caller
first_caller = com.ibm.websphere.security.WSSecurityHelper.getFirstCaller();
// Prints out the caller name
System.out.println("First caller: " + first_caller);
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
}
例えば、出力は次のようになります。jsmith
この要求に対する最初のアプリケーション・サーバーを知りたいときには、 いつでも getFirstServer メソッドを直接呼び出してください。以下のコード・サンプルでは、 getFirstServer API によって最初のアプリケーション・サーバー名が取得されます。
String first_server = null;
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try {
// Gets the first server
first_server = com.ibm.websphere.security.WSSecurityHelper.getFirstServer();
// Prints out the server name
System.out.println("First server: " + first_server);
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
}
例えば、出力は次のようになります。myManager:node1:server1
// If security is disabled on this application server,
// do not check the status of server security
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try {
// Specifies the key and values
String key = "mykey";
String value1 = "value1";
String value2 = "value2";
// Sets key, value1
com.ibm.websphere.security.WSSecurityHelper.
addPropagationAttribute (key, value1);
// Sets key, value2
String[] previous_values = com.ibm.websphere.security.WSSecurityHelper.
addPropagationAttribute (key, value2);
// Note: previous_values should contain value1
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
}
次のコード・サンプルで、getPropagationAttributes API の使い方を示します。
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try {
String key = "mykey";
String[] values = null;
// Sets key, value1
values = com.ibm.websphere.security.WSSecurityHelper.
getPropagationAttributes (key);
// Prints the values
for (int i=0; i<values.length; i++)
{
System.out.println("Value[" + i + "] = " + values[i]);
}
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
}
Value[0] = value1
Value[1] = value2
addPropagationAttribute API を使って属性を追加するには、デフォルトの PropagationToken へのカスタム属性の追加を参照してください。