IBM Data Server Driver for JDBC and SQLJ trusted context support
The IBM® Data Server Driver for JDBC and SQLJ provides methods that allow you to establish and use trusted connections in Java programs.
- IBM Data Server Driver for JDBC and
SQLJ type 4 connectivity to:
- Db2 on Linux®, UNIX, and Windows systems Version 9.5 or later
- Db2 for z/OS® Version 9.1 or later
- IBM Informix® Version 11.70 or later
- IBM Data Server Driver for JDBC and SQLJ type 2 connectivity on Db2 for z/OS Version 9.1 or later
A three-tiered application model consists of a database server, a middleware server such as WebSphere® Application Server, and end users. With this model, the middleware server is responsible for accessing the database server on behalf of end users. Trusted context support ensures that an end user's database identity and database privileges are used when the middleware server performs any database requests on behalf of that end user.
A trusted context is an object that the database administrator defines that contains a system authorization ID and a set of trust attributes. Currently, a database connection is the only type of context that is supported. The trust attributes identify a set of characteristics of a connection that are required for the connection to be considered a trusted connection. The relationship between a database connection and a trusted context is established when the connection to the database server is first created, and that relationship remains for the life of the database connection.
After a trusted context is defined, and an initial trusted connection to the data server is made, the middleware server can use that database connection under a different user without reauthenticating the new user at the database server.
To avoid vulnerability to security breaches, an application server that uses these trusted methods should not use untrusted connection methods.
- The first element contains a connection instance for the initial connection.
- The second element contains a unique cookie for the connection instance. The cookie is generated by the JDBC driver and is used for authentication during subsequent connection reuse.
- The cookie from the initial connection
- New connection properties for the reused connection
// 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);