skip to main content
Getting Started : Advanced Features : Using Connection Pooling : Using Reauthentication
  
Using Reauthentication
Typically, you can configure a connection pool to provide scalability for connections. In addition, to help minimize the number of connections required in a connection pool, you can switch the user associated with a connection to another user, a process known as reauthentication.
For example, suppose you are using Kerberos authentication to authenticate users using their operating system user name and password. To reduce the number of connections that must be created and managed, you can use reauthentication to switch the user associated with a connection to multiple users. For example, suppose your connection pool contains a connection, Conn, which was established by the user ALLUSERS. That connection can service multiple users (User A, B, and C) by switching the user associated with the connection Conn to User A, B, and C.
Not all databases support reauthentication. For databases that do, the user performing the switch must have been granted specific database permissions.
The following table shows the support for reauthentication and lists the required database permissions. Refer to your database documentation for information about granting permissions.
Table 17. Support for Reauthentication
Driver
Database
Database Permissions
DB2
DB2 V9.1 and higher for Linux/UNIX/Windows
SETSESSIONUSER
DB2 V8.1.4 and higher for Linux/UNIX/Windows
SYSADM
Oracle
Oracle8i R2 and higher 1
CONNECT THROUGH
SQL Server
Microsoft SQL Server 2005 and higher 2
IMPERSONATE

1 Oracle refers to reauthentication as proxy authentication.

2 Microsoft SQL Server refers to reauthentication as impersonation.

Note: Before performing reauthentication, applications must ensure that any statements or result sets created as one user are closed before switching the connection to another user.
To perform reauthentication on a connection explicitly, call the setCurrentUser() method in the ExtConnection interface located in the com.ddtek.jdbc.extensions package. For example, the following code switches the user on the connection from the user that created the connection (TEST) to a new user (SMITH). In addition, it sets options that switch the current schema and current database path to the schema and database path of the new user.
import com.ddtek.jdbc.extensions.*
// Get Database Connection
Connection con = DriverManager.getConnection(
   "jdbc:datadirect:db2://server1:50000;DatabaseName=jdbc", "TEST", "secret");
ExtConnection extCon = (ExtConnection)con
Properties props = new Properties();

props.put("CURRENT_SCHEMA", "SCHEMA");
props.put("CURRENT_PATH", "PATH");
ExtCon.setCurrentUser("SMITH", props);
...
See the appropriate driver chapters for information on supported options for each driver.
If you are using the DataDirect Connection Pool Manager for connection pooling, you can enable reauthentication in the Pool Manager. Refer to "Connection Pool Manager" in the DataDirect Connect Series for JDBC Reference for details.