DB2 Connection Authorization Faliure Occured Reason: Security Mechanism not supported in Java
Asked Answered
P

4

6

I am trying to configure DB2 connection with DB2JDBC Type4 drivers. But I am getting this error.

Exception in thread "main" com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException: [jcc][t4][201][11237][3.64.104] Connection authorization failure occurred. Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000

My code is

public Connection getConnection() throws ClassNotFoundException, InstantiationException,
                                         IllegalAccessException, SQLException{

   Driver driver = (Driver) Class.forName ( "com.ibm.db2.jcc.DB2Driver" ).newInstance(); 
  DriverManager.registerDriver(driver);
  Connection  connection = DriverManager.getConnection("jdbc:db2://hostname:portnumber
                                           /DBName", "username","password" );
    System.out.println( "From DAO, connection obtained " );
    return connection;  
}

Exception log:

Exception in thread "main" com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException:
[jcc][t4][201][11237][3.64.104] Connection authorization failure occurred. 
Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000
    at com.ibm.db2.jcc.am.bd.a(bd.java:677)
    at com.ibm.db2.jcc.am.bd.a(bd.java:60)
    at com.ibm.db2.jcc.am.bd.a(bd.java:120)
    at com.ibm.db2.jcc.t4.b.f(b.java:2389)
    at com.ibm.db2.jcc.t4.b.a(b.java:1712)
    at com.ibm.db2.jcc.t4.y.b(y.java:3612)
    at com.ibm.db2.jcc.t4.y.a(y.java:477)
    at com.ibm.db2.jcc.t4.y.a(y.java:117)
    at com.ibm.db2.jcc.t4.b.c(b.java:1350)
    at com.ibm.db2.jcc.t4.b.b(b.java:1221)
    at com.ibm.db2.jcc.t4.b.b(b.java:788)
    at com.ibm.db2.jcc.t4.b.a(b.java:760)
    at com.ibm.db2.jcc.t4.b.a(b.java:421)
    at com.ibm.db2.jcc.t4.b.a(b.java:396)
    at com.ibm.db2.jcc.t4.b.<init>(b.java:334)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:232)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:198)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:475)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:116)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at com.test.connection.DB2ConnectionFactory.getConnection(DB2ConnectionFactory.java:19
    at com.test.connection.ConnectionTest.main(ConnectionTest.java:18)

I also have tried these supported mechanisms by IBM Data Server Driver for JDBC and SQLJ

-CLIENT
-SERVER
-SERVER_ENCRYPT
-DATA_ENCRYPT
-KERBEROS
-GSSPLUGIN
-KRB_SERVER_ENCRYPT
-GSS_SERVER_ENCRYPT 

In order to avoid encryption problem we have deployed this application to linux box. SO in case need secure connection, but same error is occurring there.

I am using DB2 JDBC Driver version v10.1fp1_jdbc_sqlj, and I have also tried 9.5 and 9.1 and db2jcc4.jar file for this purpose.

I have also tried it using type 2 drivers, but I am getting ClassNotFound error in that case COM.ibm.db2.jdbc.app.DB2Driver. class not found.

But nothing worked so far. Any help is appreciated. I am struggling with this problem over a week.

Penicillin answered 23/5, 2013 at 4:36 Comment(0)
P
2

It's working now. The problem was with DB2. You have to make sure that your environment variables point to the correct folders. So make sure to do the following:

  • Must reboot your machine after each change or after all the change you made to your environment variables.
  • Make sure that you are using JDBC Type 2 drivers. Do not go for Type 4 unless asked by your DBA.

Will help you to make sure that your code will be able to interact with Windows JDBC Drivers

PATH=C:\Program Files\IBM\SQLLIB\BIN\db2jdbc.dll

LIB will help your code to read right libraries. i.e COM.ibm.db2.jdbc.app.DB2Driver

LIB=;C:\PROGRA~1\IBM\SQLLIB\LIB

ClassPath:

ClassPath = .;C:\PROGRA~1\IBM\SQLLIB\java\db2java.jar;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;
C:\PROGRA~1\IBM\SQLLIB\BIN\db2jdbc.dll;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;
C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cu.jar;
C:\PROGRA~1\IBM\SQLLIB\java\db2java.jar;
C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\java\jdk;
Penicillin answered 27/5, 2013 at 17:18 Comment(2)
Also must install DB2 Connect, it will automatically set your Environment Variable. But Still make sure they are correctly set and point to right foldersPenicillin
Don't forget to accept the working answer, even if it is your own.Castiron
P
0

Type 2 driver is used when you have the Data server client installed in you machine. If you are running DB2 server in the same client machine, you can you Type 2 server.

Try to use the data server client, in order to catalog the remote database in your local machine, and try to establish a connection via "db2 connect to DBName" If you can establish the connection, you can do the same in Java. If you can't, you can chanqe the catalogation options, till found the right one. Once you have done that, you can connect to the remote database.

Pemba answered 23/5, 2013 at 16:24 Comment(10)
But how about if we are deploying this application on linux box? means we do not need to set any thing there, we thought that this might be the issue on local machine, so we moved this app to dev box. But still the same issue. With DB2 jdbc type 2 drivers I am getting error that "myuserid" is not authenticated for this kind of operation.Penicillin
Exception in thread "main" com.ibm.db2.jcc.am.SqlException: [jcc][4038][12241][3.57.82] T2LUW exception: SQL1092N "UserID" does not have the authority to perform the requested command or operation. ERRORCODE=-1092, SQLSTATE=Penicillin
Have you established a connection to the database outside Java? with the same user and password. Probably, there is a configuration error in the database, I mean, there is an authentication method that does not correspond to the current implementation.Pemba
yes, I have configured the connection using DB2 client Configuration assistant, I have selected a data encrypt authentication and is working. But when I select USER_PASSWORD_AND_DATA_ENCRYPTION. its throwinf me errorPenicillin
encryptionAlgorithm can only be set with securityMechanism ENCRYPTED_PASSWORD_SECURITY and ENCRYPTED_USER_AND_PASSWORD_SECURITY.Penicillin
Ok, you cataloged the database, what about the connection? did you connect to the database?Pemba
You have to check the instance creation (Auth type), also the catalogation conf, and the security plugin in the instance if any. This is a typical conf error, but difficult to solve at distance.Pemba
Thanks for your help and time, I figured out the problem and in above post I explained what it takes.. :)Penicillin
Can you give more details, in order to share your conclusions to the community?Pemba
Sure, The problem was jdbc.dll file was not in the PATH variable. So I defined following system variables PATH=C:\Program Files\IBM\SQLLIB\BIN\db2jdbc.dll, this helps you to make sure that your code will able to interact with Windows JDBC Drivers LIB=;C:\PROGRA~1\IBM\SQLLIB\LIB LIB will help your code to read right libraries. i.e (COM.ibm.db2.jdbc.app.DB2Driver)Penicillin
A
0

I had the same issue while trying to test the data source connectivity on my linux box [Caused by: com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException: [jcc][t4][201][11237][4.26.14] Connection authorization failure occurred. Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000].

I tried changing from db2jcc4.jar to db2jcc.jar. But this is just changing the driver type from 4 to 2. I was using the db2jcc.jar version [4.26.14] which is an outdated version. Used the db2jcc4.jar of the latest version 4.33.31 fixed my issue.

Antenna answered 13/9, 2024 at 15:37 Comment(2)
So basically your answer is to simply upgrade the JDBC driver for DB2 database, correct?Inbreathe
Yes, just upgrading the jdbc driver to latest version fixed itAntenna
S
-1

What authentication method is configured on the server? Is any custom authentication plugin used? You can obtain this information by running db2 get dbm cfg on the database server.

Steal answered 23/5, 2013 at 11:55 Comment(3)
I just talked to DBA. they says they have not imposed any such mechanism. Also, in the existing SOAP application they are not using any separate authentication other than username and password.Penicillin
In the DB2 Client I am clicking option DATA_ENCRYPT in security section and is workingPenicillin
But not working through Java application. DBA told me to choose ENCRYPTED_USER_PASSOWRD, but not Working!!!!Penicillin

© 2022 - 2025 — McMap. All rights reserved.