如何在 Liberty 上使用 TLS_CLIENT_CERTIFICATE_SECURITY 选项设置 JDBC 驱动程序的安全机制 属性?

How do I set the JDBC driver's securityMechanism property with TLS_CLIENT_CERTIFICATE_SECURITY option on Liberty?

我在启动 Websphere Liberty(2015 年 7 月测试版)时尝试设置 JDBC driver's securityMechanism property with the TLS_CLIENT_CERTIFICATE_SECURITY option on Websphere Liberty® referring to the following IBM® Knowledge Center, but got a CWWKG0032W 警告消息。

你能告诉我如何在 Websphere Liberty 上使用 TLS_CLIENT_CERTIFICATE_SECURITY 选项设置 JDBC 驱动程序的 securityMechanism 属性 吗?

IBM Data Server Driver for JDBC and SQLJ support for certificate authentication

The IBM® Data Server Driver for JDBC and SQLJ provides support for client support for certificate authentication for connections to DB2® for z/OS® Version 10 or later data servers.

console.log Websphere Liberty 服务器启动时

CWWKG0032W: Unexpected value specified for property
            [securityMechanism], value = [18]. >Expected value(s) are:
            [3][4][7][9][11][12][13][15][16].

securityMechanism="18"TLS_CLIENT_CERTIFICATE_SECURITY,我通过以下确认值:

\>javac -classpath .;db2jcc4.jar; JDBCCheck
\>java -classpath .;db2jcc4.jar; JDBCCheck
  TLS_CLIENT_CERTIFICATE_SECURITY: 18

JDBC检查 class:

class JDBCCheck{
  public static void main(String args[]){
    com.ibm.db2.jcc.DB2SimpleDataSource dataSource =
                                   new com.ibm.db2.jcc.DB2SimpleDataSource();
    System.out.println( "TLS_CLIENT_CERTIFICATE_SECURITY: "
                        + dataSource.TLS_CLIENT_CERTIFICATE_SECURITY);
  }
}

server.xml:

<library id="db2-library">
  <fileset dir="lib" id="db2-fileset" includes="db2jcc4.jar db2jcc_license_cu.jar"/>
</library>

<dataSource id="db2" jndiName="jdbc/sampledb">
  <jdbcDriver libraryRef="db2-library"/>
  <properties.db2.jcc databaseName="SAMPLEDB" password="password" portNumber="10443"
              serverName="XX.XX.XX.XX" user="db2inst1" sslConnection="true"
              sslTrustStoreLocation="ssld/defaultTrustStore"
              sslTrustStorePassword="trustpassword" securityMechanism="18"/>
</dataSource>

更新 01:

基于 IBM® 知识中心中的这个主题: Java EE Full Platform 7.0 部分:事务 > 数据源 > 属性。db2.jcc

目前 WebSphere Liberty 仅支持以下 securityMechanism 值:

  • 值="3" 名称="CLEAR_TEXT_PASSWORD_SECURITY"
  • 值="4" 名称="USER_ONLY_SECURITY"
  • 值="7" 名称="ENCRYPTED_PASSWORD_SECURITY"
  • 值="9" 名称="ENCRYPTED_USER_AND_PASSWORD_SECURITY"
  • 值="11" 名称="KERBEROS_SECURITY"
  • 值="12" 名称="ENCRYPTED_USER_AND_DATA_SECURITY"
  • 值="13" 名称="ENCRYPTED_USER_PASSWORD_AND_DATA_SECURITY"
  • 值="15" 名称="PLUGIN_SECURITY"
  • 值="16" 名称="ENCRYPTED_USER_ONLY_SECURITY"

如果您想在 Liberty 中添加 TLS_CLIENT_CERTIFICATE_SECURITY 作为安全机制,我建议 opening an RFE 以便 Liberty 开发意识到支持这一点的需求。

更新:
要解决此问题,您仍然可以指定 securityMechanism="18",但只需在通用 元素中指定,而不是 db2 特定的 元素(看起来您已经想到了已经出来了)。

另一种设置TLS_CLIENT_CERTIFICATE_SECURITY的方法是:

com.ibm.db2.jcc.DB2SimpleDataSource dataSource = new 
                                    com.ibm.db2.jcc.DB2SimpleDataSource();
dataSource.setSecurityMechanism 
           (com.ibm.db2.jcc.DB2BaseDataSource.TLS_CLIENT_CERTIFICATE_SECURITY);

查看此 IBM® 知识中心以获取更多信息:

IBM Data Server Driver for JDBC and SQLJ support for certificate authentication

这应该适用于 Websphere Full Profile 和 Websphere Liberty Profile。

这里是使用用户标识和加密密码设置安全机制以建立 DB2 连接的代码。传递用户名、密码和 url 字符串。

Properties properties = new Properties(); // Create a Properties object
    properties.put("user", user);          // Set user ID for the connection
    properties.put("password", password);      // Set password for the connection
    properties.put("securityMechanism", 
      new String("" + 
      DB2BaseDataSource.ENCRYPTED_USER_AND_PASSWORD_SECURITY +
      ""));
                                              // Set security mechanism to 
                                              // user ID and encrypted password
    properties.put("encryptionAlgorithm", "2");

    Connection connection = DriverManager.getConnection("jdbc:db2://" + url, properties);