I am trying to set up a JDBC using DataSource interface, DB2 database and Kerberos for authentication. I am using IBMs documentation which refers in Kerberos security with no user ID or password link here.
Code block for DataSource
DB2SimpleDataSource dataSource = new DB2SimpleDataSource();
dataSource.setDriverType(4);
dataSource.setServerName("server");
dataSource.setPortNumber(portnumber);
dataSource.setDatabaseName("database name");
dataSource.setSslConnection(true);
dataSource.setClientProgramName("program name");
dataSource.setRetrieveMessagesFromServerOnGetMessage(true);
dataSource.setSecurityMechanism(dataSource.KERBEROS_SECURITY);
I have the following error in my console:
Error message
com.ibm.db2.jcc.am.SqlException: [jcc][t4][10262][11223][4.19.49] Unexpected Throwable caught: class com.ibm.db2.jcc.am.le (in unnamed module @0x49097b5d) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x49097b5d. ERRORCODE=-4228, SQLSTATE=null
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.b(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.<init>(Unknown Source)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
at test.connection.TestDbConnectionDataSource.main(TestDbConnectionDataSource.java:81)
Caused by: java.lang.IllegalAccessError: class com.ibm.db2.jcc.am.le (in unnamed module @0x49097b5d) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x49097b5d
at com.ibm.db2.jcc.am.le.a(Unknown Source)
at com.ibm.db2.jcc.am.le.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
I am not using the dataSource.setKerberosServerPrincipal("sample/[email protected]");
which refers in IBM doc. Moreover, I am using many realm which I have to replace the @SRVLSJ.SJ.IBM.COM
.
For this reason I am using the System.setProperty("java.security.krb5.conf", "path\krb5.conf");
The adove error I can resolve this error if I use in VM arguments this: --add-exports java.base/sun.security.action=ALL-UNNAMED
. But, I am searching a way to still work without this in VM arguments.
Last details. I am using com.ibm.db2.jcc.DB2SimpleDataSource interface. The version of DB2 is 4.19.49, jdk 17.0.6, Kerberos 5.