IBM Data Server Driver for JDBC and SQLJ のトラステッド・コンテキストのサポート

これは、 IBM® Data Server Driver for JDBC and SQLJ Javaプログラムで信頼できる接続を確立し、使用するためのメソッドを提供します。

トラステッド接続は、以下の場合にサポートされます。
  • IBM Data Server Driver for JDBC and SQLJ タイプ4の接続先:
    • Db2 Linux®、UNIX、Windowsシステム上で バージョン 9.5 以降
    • Db2 for z/OS® バージョン 9.1 以降
    • IBM Informix® バージョン 11.70 以降
  • Db2 for z/OS バージョン 9.1 以降での IBM Data Server Driver for JDBC and SQLJ タイプ 2 接続

3層アプリケーションモデルは、データベースサーバー、 WebSphere® Application Server などのミドルウェアサーバー、そしてエンドユーザーで構成されています。 このモデルでは、ミドルウェア・サーバーがエンド・ユーザーに代わってデータベース・サーバーにアクセスします。 トラステッド・コンテキストのサポートにより、ミドルウェア・サーバーがエンド・ユーザーに代わって任意のデータベース要求を実行する際に、エンド・ユーザーのデータベース ID とデータベース特権が使用されます。

トラステッド・コンテキストとは、データベース管理者が定義し、システムの許可 ID およびトラスト属性のセットが含まれたオブジェクトのことです。 現在、サポートされているコンテキストの唯一のタイプは、データベース接続です。 トラスト属性により、接続がトラステッド接続と見なされるために必要な接続の特性のセットが識別されます。 データベース接続とトラステッド・コンテキストの間の関係は、データベース・サーバーへの接続が最初に作成されたときに確立され、この関係はデータベース接続が存続する間持続します。

トラステッド・コンテキストが定義され、データ・サーバーとの初期トラステッド接続が確立された後、ミドルウェア・サーバーはデータベース・サーバーで新しいユーザーを再認証することなく、そのデータベース接続を別のユーザーの下で使用できます。

セキュリティー・ブリーチ (抜け穴) へのぜい弱性を避けるために、これらのトラステッド・メソッドを使用するアプリケーション・サーバーでは、非トラステッド接続メソッドを使用しないでください。

DB2ConnectionPoolDataSource クラスでは getDB2TrustedPooledConnection メソッドのいくつかのバージョンが提供され、また DB2XADataSource クラスでは getDB2TrustedXAConnection メソッドのいくつかのバージョンが提供され、これらによってアプリケーション・サーバーでの初期トラステッド接続の確立が可能になります。 受け渡す接続プロパティーのタイプ、および Kerberos セキュリティーを使用するかどうかに基づいて、メソッドを選択します。 アプリケーションサーバーがこれらのメソッドのいずれかを呼び出すと、 IBM Data Server Driver for JDBC and SQLJ 2つの要素を持つObject[]配列を返します
  • 最初のエレメントには、初期接続用の接続インスタンスが含まれています。
  • 2 番目のエレメントには、接続インスタンス用の固有の cookie が含まれています。 この cookie は JDBC ドライバーによって生成され、その後の接続の再利用時に認証用に使用されます。
DB2PooledConnection クラスでは getDB2Connection メソッドのいくつかのバージョンが提供され、また DB2Connection クラスでは reuseDB2Connection メソッドのいくつかのバージョンが提供されます。これらによって、新規ユーザーの代わりにアプリケーション・サーバーで既存のトラステッド接続の再利用が可能になります。 アプリケーション・サーバーでは、これらのメソッドの 1 つが使用されて以下の項目が新規ユーザーに受け渡されます。
  • 初期接続からの cookie
  • 再利用される接続用の新規接続プロパティー
JDBC ドライバーは、提供された cookie が基礎となるトラステッド物理接続の cookie と一致することを調べて、接続要求がそのトラステッド物理接続を確立したアプリケーション・サーバーから発信されていることを確認します。 cookie が一致する場合、新規プロパティーを持つ接続が使用可能になり、この新規ユーザーが即時使用することができます。
例: 初期トラステッド接続の取得:
// Create a DB2ConnectionPoolDataSource instance
com.ibm.db2.jcc.DB2ConnectionPoolDataSource dataSource = 
  new com.ibm.db2.jcc.DB2ConnectionPoolDataSource();
// Set properties for this instance
dataSource.setDatabaseName ("STLEC1");
dataSource.setServerName ("v7ec167.svl.ibm.com");
dataSource.setDriverType (4);
dataSource.setPortNumber(446);
java.util.Properties properties = new java.util.Properties();
// Set other properties using 
// properties.put("property", "value");
// Supply the user ID and password for the connection
String user = "user";
String password = "password";
// Call getDB2TrustedPooledConnection to get the trusted connection
// instance and the cookie for the connection
Object[] objects = dataSource.getDB2TrustedPooledConnection(
                         user,password, properties);
例: 既存のトラステッド接続の再利用:
// The first item that was obtained from the previous getDB2TrustedPooledConnection
// call is a connection object. Cast it to a PooledConnection object.
javax.sql.PooledConnection pooledCon = 
  (javax.sql.PooledConnection)objects[0];
properties = new java.util.Properties();
// Set new properties for the reused object using 
// properties.put("property", "value");
// The second item that was obtained from the previous getDB2TrustedPooledConnection
// call is the cookie for the connection. Cast it as a byte array.
byte[] cookie = ((byte[])(objects[1]);
// Supply the user ID for the new connection.
String newUser = "newuser"; 
// Supply the password for the new connection
// Use null when authentication is not required
String newPassword = null;
// Supply the name of a mapping service that maps a workstation user 
// ID to a z/OS RACF ID 
String userRegistry = "registry";
// Do not supply any security token data to be traced.
byte[] userSecTkn = null;
// Do not supply a previous user ID.
String originalUser = null;
// Call getDB2Connection to get the connection object for the new
// user.
java.sql.Connection con =
  ((com.ibm.db2.jcc.DB2PooledConnection)pooledCon).getDB2Connection(
     cookie,newUser,newPassword,userRegistry,userSecTkn,originalUser,properties);