Connect java with PostgreSQL using SSPI authentication.
Installed PostgreSQL using SSPI authentication (version: 16.3). I am able to connect using pgAdmin4 tool. I'm attempting to connect java with PostgreSQL.
I modified the pg_hba.conf to enable SSPI connection.
host all dbadmin 172.16.8.212/32 sspi map=SSPI
host all dbadmin ::1/128 sspi map=SSPI
The following JAR files are being used for Java connectivity:
1. postgresql.jdbc3.jar (version 42.7.2)
2. waffle-jna-1.9.0 (version 1.9.0)
3. jna-4.5.2 (version 4.5.2)
4. jna-platform-4.5.2 (version 4.5.2 (b0))
Url used for connectivity:
url = "jdbc:postgresql://172.16.8.212:5432/postgres?gsslib=sspi&sspiServiceClass=POSTGRES";
Connection conn = DriverManager.getConnection(url, props) //where props have only username.
Exception I got:
org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.
at org.postgresql.Driver.connect(Driver.java:320)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at PostgresSSPIExample.main(PostgresSSPIExample.java: 11)
Caused by: java.lang.RuntimeException: NTDSAPI DsMakeSpn call failed with 87
at org.postgresql.sspi.NTDSAPIWrapper.DsMakeSpn(NTDSA PIWrapper.java:48)
at org.postgresql.sspi.SSPIClient.makeSPN(SSPIClient. java:134)
at org.postgresql.sspi.SSPIClient.startSSPI(SSPIClien t.java:180)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAut hentication(ConnectionFactoryImpl.java:811)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryCo nnect(ConnectionFactoryImpl.java:203)
at org.postgresql.core.v3.ConnectionFactoryImpl.openC onnectionImpl(ConnectionFactoryImpl.java:258)
at org.postgresql.core.ConnectionFactory.openConnecti on(ConnectionFactory.java:54)
at org.postgresql.jdbc.PgConnection.<init>(PgConnecti on.java:263)
at org.postgresql.Driver.makeConnection(Driver.java:4 44)
at org.postgresql.Driver.connect(Driver.java:297)
... 3 more
Is this driver problem or setup problem?
I used latest driver version also. But nothing seems to work.