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 およびトラスト属性のセットが含まれたオブジェクトのことです。 現在、サポートされているコンテキストの唯一のタイプは、データベース接続です。 トラスト属性により、接続がトラステッド接続と見なされるために必要な接続の特性のセットが識別されます。 データベース接続とトラステッド・コンテキストの間の関係は、データベース・サーバーへの接続が最初に作成されたときに確立され、この関係はデータベース接続が存続する間持続します。
トラステッド・コンテキストが定義され、データ・サーバーとの初期トラステッド接続が確立された後、ミドルウェア・サーバーはデータベース・サーバーで新しいユーザーを再認証することなく、そのデータベース接続を別のユーザーの下で使用できます。
セキュリティー・ブリーチ (抜け穴) へのぜい弱性を避けるために、これらのトラステッド・メソッドを使用するアプリケーション・サーバーでは、非トラステッド接続メソッドを使用しないでください。
- 最初のエレメントには、初期接続用の接続インスタンスが含まれています。
- 2 番目のエレメントには、接続インスタンス用の固有の cookie が含まれています。 この cookie は JDBC ドライバーによって生成され、その後の接続の再利用時に認証用に使用されます。
- 初期接続からの 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);