IBM Data Server Driver for JDBC and SQLJ 下的 Kerberos 安全性

JDBC Kerberos 安全支持仅适用于 IBM® 4型连接 Data Server Driver for JDBC and SQLJ

为了启用 JDBC 对 Kerberos 安全的支持,您还需要启用Java软件开发工具包(SDK)的以下组件:
  • Java加密扩展
  • Java 类属安全性服务 (JGSS)
  • Java 认证和授权服务 (Java Authentication and Authorization Service, JAAS)

请参阅您的Java SDK文档,了解如何启用这些组件。

可以通过三种方式为连接指定 Kerberos 安全性:
  • 使用用户标识和密码
  • 没有用户标识或密码
  • 使用委托凭证

具有用户标识和密码的 Kerberos 安全性

对于这种情况,Kerberos 使用指定的用户标识和密码来获取授予凭单的凭单 (TGT),以允许您向数据库服务器进行认证。

您需要设置 userpasswordkerberosServerPrincipalsecurityMechanism 属性。 将 securityMechanism 属性设置为 com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY (11)。 kerberosServerPrincipal 属性指定数据库服务器向 Kerberos 密钥分发中心 (KDC) 注册的主体名称。

对于 DriverManager 界面 :通过在 Properties 对象中设置 userpasswordkerberosServerPrincipalsecurityMechanism 属性,然后调用包含 Properties 对象作为参数的 getConnection 方法的形式,来设置用户ID、密码、 Kerberos 服务器和安全机制。 例如,使用类似这样的代码来设置具有用户标识和密码的 Kerberos 安全性机制:
import java.sql.*;                        // JDBC base
import com.ibm.db2.jcc.*;                 // IBM Data Server Driver for JDBC
                                          // and SQLJ implementation of JDBC
…
Properties properties = new Properties(); // Create a Properties object
properties.put("user", "db2adm");         // Set user ID for the connection
properties.put("password", "db2adm");     // Set password for the connection
properties.put("kerberosServerPrincipal", 
  "sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
                                          // Set the Kerberos server
properties.put("securityMechanism", 
  new String("" + 
  com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY + "")); 
                                          // Set security mechanism to 
                                          // Kerberos
String url = "jdbc:db2://mvs1.sj.ibm.com:5021/san_jose";
                                          // Set URL for the data source
Connection con = DriverManager.getConnection(url, properties); 
                                          // Create the connection
对于 DataSource 接口 :如果您创建并部署了 DataSource 对象,请在创建 DataSource 对象后调用 DataSource.setKerberosServerPrincipalDataSource.setSecurityMechanism 方法来设置 Kerberos 服务器和安全机制。 例如:
import java.sql.*;                        // JDBC base
import com.ibm.db2.jcc.*;                 // IBM Data Server Driver for JDBC
                                          // and SQLJ implementation of JDBC
…
com.ibm.db2.jcc.DB2SimpleDataSource db2ds =  
  new com.ibm.db2.jcc.DB2SimpleDataSource();
                                          // Create the DataSource object
db2ds.setDriverType(4);                   // Set the driver type
db2ds.setDatabaseName("san_jose");        // Set the location
db2ds.setUser("db2adm");                  // Set the user
db2ds.setPassword("db2adm");              // Set the password
db2ds.setServerName("mvs1.sj.ibm.com");  
                                          // Set the server name
db2ds.setPortNumber(5021);                // Set the port number
db2ds.setKerberosServerPrincipal(
  "sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
                                          // Set the Kerberos server
db2ds.setSecurityMechanism(
  com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY);
                                          // Set security mechanism to
                                          // Kerberos

没有用户标识或密码的 Kerberos 安全性

对于这种情况,Kerberos 缺省凭证高速缓存必须包含授予凭单的凭单 (TGT),以允许您向数据库服务器进行认证。

您需要设置 securityMechanism 属性。 将 securityMechanism 属性设置为 com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY (11)。 设置 kerberosServerPrincipal 属性是可选的。

对于 DriverManager 界面 :通过在 Properties 对象中设置 kerberosServerPrincipalsecurityMechanism 属性来设置 Kerberos 服务器和安全机制,然后调用 getConnection 方法的表单,该表单将 Properties 对象作为参数。 例如,使用这样的代码来设置不带用户标识和密码的 Kerberos 安全机制:
import java.sql.*;                        // JDBC base
import com.ibm.db2.jcc.*;                 // IBM Data Server Driver for JDBC
                                          // and SQLJ implementation of JDBC
…
Properties properties = new Properties(); // Create a Properties object
properties.put("kerberosServerPrincipal", 
  "sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
                                          // Set the Kerberos server
properties.put("securityMechanism", 
  new String("" + 
  com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY + "")); 
                                          // Set security mechanism to 
                                          // Kerberos
String url = "jdbc:db2://mvs1.sj.ibm.com:5021/san_jose";
                                          // Set URL for the data source
Connection con = DriverManager.getConnection(url, properties); 
                                          // Create the connection
对于 DataSource 接口 :如果您创建并部署了 DataSource 对象,请在创建 DataSource 对象后调用 DataSource.setKerberosServerPrincipalDataSource.setSecurityMechanism 方法来设置 Kerberos 服务器和安全机制。 例如:
import java.sql.*;                        // JDBC base
import com.ibm.db2.jcc.*;                 // IBM Data Server Driver for JDBC
                                          // and SQLJ implementation of JDBC
…
DB2SimpleDataSource db2ds = 
  new com.ibm.db2.jcc.DB2SimpleDataSource();
                                          // Create the DataSource object
db2ds.setDriverType(4);                   // Set the driver type
db2ds.setDatabaseName("san_jose");        // Set the location
db2ds.setServerName("mvs1.sj.ibm.com");  
                                          // Set the server name
db2ds.setPortNumber(5021);                // Set the port number
db2ds.setKerberosServerPrincipal(
  "sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
                                          // Set the Kerberos server
db2ds.setSecurityMechanism(
  com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY);
                                          // Set security mechanism to
                                          // Kerberos

具有来自另一个主体的授权凭证的 Kerberos 安全性

对于这种情况,您将使用另一个主体传递给您的委托凭证向数据库服务器进行认证。

您需要设置 kerberosServerPrincipalgssCredentialsecurityMechanism 属性。 将 securityMechanism 属性设置为 com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY (11)。

对于 DriverManager 界面 :通过在 Properties 对象中设置 kerberosServerPrincipalsecurityMechanism 属性,设置 Kerberos 服务器、委托凭证和安全机制。 然后调用 getConnection 方法,该方法将 Properties 对象作为参数。 例如,使用这样的代码来设置不带用户标识和密码的 Kerberos 安全机制:
import java.sql.*;                        // JDBC base
import com.ibm.db2.jcc.*;                 // IBM Data Server Driver for JDBC
                                          // and SQLJ implementation of JDBC
…
Properties properties = new Properties(); // Create a Properties object
properties.put("kerberosServerPrincipal", 
  “sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
                                          // Set the Kerberos server
properties.put("gssCredential",delegatedCredential);
                                          // Set the delegated credential
properties.put("securityMechanism", 
  new String("" + 
    com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY + "")); 
                                          // Set security mechanism to 
                                          // Kerberos
String url = "jdbc:db2://mvs1.sj.ibm.com:5021/san_jose";
                                          // Set URL for the data source
Connection con = DriverManager.getConnection(url, properties); 
                                          // Create the connection
对于 DataSource 接口 :如果您创建并部署了 DataSource 对象,请在创建 DataSource 对象后调用 DataSource.setKerberosServerPrincipalDataSource.setGssCredentialDataSource.setSecurityMechanism 方法来设置 Kerberos 服务器、委托凭证和安全机制。 例如:
DB2SimpleDataSource db2ds = new com.ibm.db2.jcc.DB2SimpleDataSource();
                                             // Create the DataSource object
db2ds.setDriverType(4);                      // Set the driver type
db2ds.setDatabaseName("san_jose");           // Set the location
db2ds.setServerName("mvs1.sj.ibm.com");  // Set the server name
db2ds.setPortNumber(5021);                   // Set the port number
db2ds.setKerberosServerPrincipal(
  "sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM");
                                             // Set the Kerberos server
db2ds.setGssCredential(delegatedCredential);
                                             // Set the delegated credential
db2ds.setSecurityMechanism(
  com.ibm.db2.jcc.DB2BaseDataSource.KERBEROS_SECURITY);
                                             // Set security mechanism to
                                             // Kerberos