4 DB2 Driver : Authentication

Authentication
Authentication protects the identity of the user so that user credentials cannot be intercepted by malicious hackers when transmitted over the network. See “Authentication” for an overview.
The DB2 driver supports the following methods of authentication:
■
User ID/password authentication authenticates the user to the database using a user ID and password. Depending on the method you specify, the driver passes one of the following sets of credentials to the DB2 database server for authentication:
●
●
●
■
Kerberos authentication uses Kerberos, a trusted third-party authentication service, to verify user identities. Kerberos authentication can take advantage of the user ID and password maintained by the operating system to authenticate users to the database or use another set of user credentials specified by the application.
This method requires knowledge of how to configure your Kerberos environment and supports Windows Active Directory Kerberos and MIT Kerberos.
■
Client authentication uses the user ID of the user logged onto the system on which the driver is running to authenticate the user to the database. The DB2 database server relies on the client to authenticate the user and does not provide additional authentication.
NOTE: Because the database server does not authenticate the user, use this method of authentication if you can guarantee that only trusted clients can access the database server.
See “Using the AuthenticationMethod Property” for information about configuring the driver for authentication and encrypting user IDs and passwords.
Using the AuthenticationMethod Property
The AuthenticationMethod connection property controls which authentication mechanism the driver uses when establishing connections.
When AuthenticationMethod=clearText (default), AuthenticationMethod=encryptedPassword, AuthenticationMethod=encryptedPasswordAES, AuthenticationMethod=encryptedUIDPassword, or AuthenticationMethod=encrytpedUIDPasswordAES, the driver uses user ID/password authentication when establishing a connection. The User property provides the user ID. The Password property provides the password.
The set of credentials that are passed to the DB2 server depend on the specified value:
■
When AuthenticationMethod=clearText, both a user ID and a password are sent in clear text to the DB2 server for authentication.
■
When AuthenticationMethod=encryptedPassword or AuthenticationMethod=encryptedPasswordAES, a user ID in clear text and an encrypted password are sent to the DB2 server for authentication.
■
When AuthenticationMethod=encryptedUIDPassword or AuthenticationMethod=encryptedUIDPasswordAES, an encrypted user ID and encrypted password are sent to the DB2 server for authentication.
The encryption method that is used for user IDs and passwords is negotiated during the connection process. For DB2 9.7 for Linux/UNIX/Windows, the method used to encrypt user IDs and passwords is either AES or DES encryption depending on the setting of the alternate_auth_enc parameter on the DB2 server. For all other DB2 databases, the method is DES encryption. See the description for the AuthenticationMethod property for more information.
NOTE: The driver also can use data encryption by setting the EncryptionMethod property.
When AuthenticationMethod=client, the driver uses the user ID of the user logged onto the system on which the driver is running when establishing a connection. The DB2 database server relies on the client to authenticate the user and does not provide additional authentication. The driver ignores any values specified by the User property and Password properties.
When AuthenticationMethod=kerberos, the driver uses Kerberos authentication when establishing a connection. The driver ignores any values specified by the User property and Password properties.
Configuring User ID/Password Authentication
1
Set the AuthenticationMethod property to clearText (default), encryptedPassword, encryptedPasswordAES, encryptedUIDPassword, or encryptedUIDPasswordAES.
2
3
Configuring Kerberos Authentication
This section provides requirements and instructions for configuring Kerberos authentication for the DB2 driver.
Product Requirements
Verify that your environment meets the requirements listed in Table 4-3 before you configure the driver for Kerberos authentication.
Database server
The Kerberos server is the machine where the user IDs for authentication are administered. The Kerberos server is also the location of the Kerberos KDC.
Configuring the Driver
During installation, the following files required for Kerberos authentication are installed in the /lib subdirectory of your product installation directory:
■
krb5.conf is a Kerberos configuration file containing values for the Kerberos realm and the KDC name for that realm. A generic file is installed that you must modify for your environment.
■
JDBCDriverLogin.conf file is a configuration file that specifies which Java Authentication and Authorization Service (JAAS) login module to use for Kerberos authentication. This file loads automatically unless the java.security.auth.login.config system property is set to load another login configuration file. You can edit this file, but the driver must be able to find the JDBC_DRIVER_01 entry to configure the JAAS login module. Refer to your J2SE documentation for information about setting options in this file.
To configure the driver:
1
2
Modify the krb5.conf file to contain your Kerberos realm name and the KDC name for that Kerberos realm by editing the file with a text editor or by specifying the system properties, java.security.krb5.realm and java.security.krb5.kdc.
NOTE: If using Windows Active Directory, the Kerberos realm name is the Windows domain name and the KDC name is the Windows domain controller name.
For example, if your Kerberos realm name is XYZ.COM and your KDC name is kdc1, your krb5.conf file would look like this:
[libdefaults]
default_realm = XYZ.COM
 
[realms]
XYZ.COM = {
kdc = kdc1
}
If the krb5.conf file does not contain a valid Kerberos realm and KDC name, the following exception is thrown:
Message:[DataDirect][DB2 JDBC Driver]Could not establish a connection using integrated security: No valid credentials provided
The krb5.conf file loads automatically unless the java.security.krb5.conf system property is set to load another Kerberos configuration file.
3
Specifying User Credentials for Kerberos Authentication (Delegation of Credentials)
By default, when Kerberos authentication is used, the DB2 driver takes advantage of the user name and password maintained by the operating system to authenticate users to the database. By allowing the database to share the user name and password used for the operating system, users with a valid operating system account can log into the database without supplying a user name and password.
Many application servers or Web servers act on behalf of the client user logged on the machine on which the application is running, rather than the server user. If you want the driver to use user credentials other than the server user’s operating system credentials, include code in your application to obtain and pass a javax.security.auth.Subject used for authentication as shown in the following example.
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import java.sql.*;
 
// The following code creates a javax.security.auth.Subject instance
// used for authentication. Refer to the Java Authentication
// and Authorization Service documentation for details on using a
// LoginContext to obtain a Subject.
 
LoginContext lc = null;
Subject subject = null;
 
try {
 
   lc = new LoginContext("JaasSample", new TextCallbackHandler());
   lc.login();
   subject = lc.getSubject();
}
catch (Exception le) {
   ... // display login error
}
 
// This application passes the javax.security.auth.Subject
// to the driver by executing the driver code as the subject
 
Connection con =
   (Connection) Subject.doAs(subject, new PrivilegedExceptionAction() {
   public Object run() {
      Connection con = null;
      try {
 
         Class.forName("com.ddtek.jdbc.db2.DB2Driver");
         String url = "jdbc:datadirect:db2://myServer:50000;DatabaseName=jdbc";
         con = DriverManager.getConnection(url);
         }
      catch (Exception except) {
 
      ... //log the connection error
      Return null;
      }
       return con;
   }
});
 
// This application now has a connection that was authenticated with
// the subject. The application can now use the connection.
Statement stmt = con.createStatement();
String sql = "SELECT * FROM employee";
ResultSet rs = stmt.executeQuery(sql);
 
... // do something with the results
Obtaining a Kerberos Ticket Granting Ticket
To use Kerberos authentication, the application user first must obtain a Kerberos Ticket Granting Ticket (TGT) from the Kerberos server. The Kerberos server verifies the identity of the user and controls access to services using the credentials contained in the TGT.
If the application uses Kerberos authentication from a Windows client, the application user does not need to explicitly obtain a TGT. Windows Active Directory automatically obtains a TGT for the user.
If the application uses Kerberos authentication from a UNIX or Linux client, the user must explicitly obtain a TGT. To explicitly obtain a TGT, the user must log onto the Kerberos server using the kinit command. For example, the following command requests a TGT from the server with a lifetime of 10 hours, which is renewable for 5 days:
kinit -l 10h -r 5d user
where user is the application user.
Refer to your Kerberos documentation for more information about using the kinit command and obtaining TGTs for users.
Configuring Client Authentication
Set the AuthenticationMethod property to a value of client.