Thread: Are these bugs?
Dear Sirs,
I was trying to use postgresql jdbc. The downloaded version did not work for me so I tried to build the project myself using Eclipse (the suggested gradle build method gave me errors).
I have encountered several problems:
1) Download the source from jdbc.posgresql.org, this source does not have the SSPIClient implementation (it only has the ISSPIClient interface).
2) Downloaded the source from github. This version does not have the souce code for org.postgresql.util.DriverInfo.java. I copied it from the downloaded file from step 1) above.
3) After adding all the missing external libraries (such as jna, waffle, osgi...) it compiled successfully.
4) There are run time errors after testing the built library with a small test program:
(4.1) If jna and jna-platform are of version 5.0.0 or newer, the following line causes errors because no such a constructor exists:
SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, receivedToken);
Note: Verson 5.0.0 (or newer) has only one constructor SecBufferDesc().
(4.2) If jna and jna-platform are of older version (4.5.2), SecBufferDesc does provide 3 different constructor, but the following code causes errors:
Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");
This class references SspiUtil$ManagedSecBufferDesc, which is only available from version 5.0.0 of jna-platform (or newer).
So basically the implementation of SSPIClient uses different JNA APIs from incompatible versions.
Would you please take a look?
Thanks,
Brian Ye
Thanks,
Brian Ye
Hello Brian,
See my answers below
Dave Cramer
www.postgres.rocks
On Sat, 7 Aug 2021 at 11:50, Brian Ye <brian.y.ye@gmail.com> wrote:
Dear Sirs,I was trying to use postgresql jdbc. The downloaded version did not work for me so I tried to build the project myself using Eclipse (the suggested gradle build method gave me errors).
Why did the download version not work? Can you elaborate.
What errors were encountered when you tried to build it?
I have encountered several problems:1) Download the source from jdbc.posgresql.org, this source does not have the SSPIClient implementation (it only has the ISSPIClient interface).
Interesting. I can confirm that it does not exist. I will rectify this.
2) Downloaded the source from github. This version does not have the souce code for org.postgresql.util.DriverInfo.java. I copied it from the downloaded file from step 1) above.
https://github.com/pgjdbc/pgjdbc/archive/refs/tags/REL42.2.23.tar.gz does have DriverInfo
3) After adding all the missing external libraries (such as jna, waffle, osgi...) it compiled successfully.4) There are run time errors after testing the built library with a small test program:(4.1) If jna and jna-platform are of version 5.0.0 or newer, the following line causes errors because no such a constructor exists:SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, receivedToken);Note: Verson 5.0.0 (or newer) has only one constructor SecBufferDesc().(4.2) If jna and jna-platform are of older version (4.5.2), SecBufferDesc does provide 3 different constructor, but the following code causes errors:Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");This class references SspiUtil$ManagedSecBufferDesc, which is only available from version 5.0.0 of jna-platform (or newer).So basically the implementation of SSPIClient uses different JNA APIs from incompatible versions.Would you please take a look?
I can, but if you can provide your test program that would be helpful
Dave
Thanks,
Brian Ye
Hi, Dave,
Thanks for your reply.
I am out of town this week, and will provide the information when I come back.
Best regards,
Brian Ye
On Sun, Aug 8, 2021, 5:53 AM Dave Cramer <davecramer@postgres.rocks> wrote:
Hello Brian,See my answers belowDave Cramerwww.postgres.rocksOn Sat, 7 Aug 2021 at 11:50, Brian Ye <brian.y.ye@gmail.com> wrote:Dear Sirs,I was trying to use postgresql jdbc. The downloaded version did not work for me so I tried to build the project myself using Eclipse (the suggested gradle build method gave me errors).Why did the download version not work? Can you elaborate.What errors were encountered when you tried to build it?I have encountered several problems:1) Download the source from jdbc.posgresql.org, this source does not have the SSPIClient implementation (it only has the ISSPIClient interface).Interesting. I can confirm that it does not exist. I will rectify this.2) Downloaded the source from github. This version does not have the souce code for org.postgresql.util.DriverInfo.java. I copied it from the downloaded file from step 1) above.https://github.com/pgjdbc/pgjdbc/archive/refs/tags/REL42.2.23.tar.gz does have DriverInfo3) After adding all the missing external libraries (such as jna, waffle, osgi...) it compiled successfully.4) There are run time errors after testing the built library with a small test program:(4.1) If jna and jna-platform are of version 5.0.0 or newer, the following line causes errors because no such a constructor exists:SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, receivedToken);Note: Verson 5.0.0 (or newer) has only one constructor SecBufferDesc().(4.2) If jna and jna-platform are of older version (4.5.2), SecBufferDesc does provide 3 different constructor, but the following code causes errors:Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");This class references SspiUtil$ManagedSecBufferDesc, which is only available from version 5.0.0 of jna-platform (or newer).So basically the implementation of SSPIClient uses different JNA APIs from incompatible versions.Would you please take a look?I can, but if you can provide your test program that would be helpfulDave
Thanks,
Brian Ye
Hi Dave,
Thanks for your reply.
Please see my inline responses below.
Best regards,
Brian Ye
On Sat, 7 Aug 2021 at 11:50, Brian Ye <brian.y.ye@gmail.com> wrote:Dear Sirs,I was trying to use postgresql jdbc. The downloaded version did not work for me so I tried to build the project myself using Eclipse (the suggested gradle build method gave me errors).Why did the download version not work? Can you elaborate.
Before answering this question, let me give some background information so that we are sure that postgresql with kerberos support works in my Windows environment (using SSPI).
I have the PostgreSQL server running as a service:

For both IPV4 and IPV6, I configured the login for my account ( briany@CORP) to use SSPI:
#ipv4
#ipv6
host all briany@CORP ::/0 sspi
The SPN was registered:
Registered ServicePrincipalNames for CN=Brian Ye,CN=Users,DC=corp,DC=whamtech,DC=com:
postgres/by64.corp.whamtech.com:5432
Now I use "psql" utility to login using Kerberos:
D:\Programs\PostgreSQL\13\data>psql -U briany@CORP -d postgres
psql (13.1)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=> \dt
List of relations
Schema | Name | Type | Owner
--------+-------------+-------+----------
public | simpletable | table | postgres
(1 row)
postgres=>
So it works.
I also configured ODBC using Kerberos, it also worked:


I downloaded the jdbc driver (postgresql-42.2.23.jar), and use the following simple test code to connect:
try {
java.util.Properties info = new java.util.Properties();
info.setProperty("user", "postgres"); // LINE a
info.setProperty("password", "postgres"); // LINE b
//info.setProperty("user", "briany@CORP"); // LINE c
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection
(
"jdbc:postgresql://by64:5432/", // LINE d
info
);
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
It works this way (using password).
If I comment oout LINE a and LINE b, uncomment LINE c (to use a different account that requies Kerberos login), running this program produces the following:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/Win32Exception
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at org.postgresql.core.v3.ConnectionFactoryImpl.createSSPI(ConnectionFactoryImpl.java:82)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:712)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:161)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
at org.postgresql.Driver.makeConnection(Driver.java:465)
at org.postgresql.Driver.connect(Driver.java:264)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)
at PostgreSQLJDBC.main(PostgreSQLJDBC.java:21)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.win32.Win32Exception
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more
I also downloaded jna, waffle libraries and tried it:
D:\Users\briany\test\java\jdbc\PostgreSQLJDBC_sspi>java -cp C:\Users\briany\Downloads\postgresql-42.2.23.jarlC:\users\briany\Downloads\jna-4.5.2.jar;C:\users\briany\Downloads\jna-platform-4.5.2.jar;C:\Users\briany\Downloads\waffle-jna-3.0.jar;. -Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=c:\windows\krb5.ini PostgreSQLJDBC
java.lang.ClassNotFoundException: org.postgresql.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at PostgreSQLJDBC.main(PostgreSQLJDBC.java:18)
java.lang.ClassNotFoundException: org.postgresql.Driver
Changing LINE d to
"jdbc:postgresql://by64:5432/briany?kerberosServerName=postgres&jaasApplicationName=pgjdbc&user=briany/by64.corp.whamtech.com:5432",
resulted in the same error:
"D:\Users\briany\test\java\jdbc\PostgreSQLJDBC_sspi>java -cp C:\Users\briany\Downloads\postgresql-42.2.23.jarlC:\users\briany\Downloads\jna-4.5.2.jar;C:\users\briany\Downloads\jna-platform-4.5.2.jar;C:\Users\briany\Downloads\waffle-jna-3.0.jar;. -Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=c:\windows\krb5.ini PostgreSQLJDBC
java.lang.ClassNotFoundException: org.postgresql.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at PostgreSQLJDBC.main(PostgreSQLJDBC.java:18)
java.lang.ClassNotFoundException: org.postgresql.Driver
What errors were encountered when you tried to build it?
I can finally compile the package after adding the following into the build path, but have the run-time errors as described in the item 4) below.

I have encountered several problems:1) Download the source from jdbc.posgresql.org, this source does not have the SSPIClient implementation (it only has the ISSPIClient interface).Interesting. I can confirm that it does not exist. I will rectify this.2) Downloaded the source from github. This version does not have the souce code for org.postgresql.util.DriverInfo.java. I copied it from the downloaded file from step 1) above.https://github.com/pgjdbc/pgjdbc/archive/refs/tags/REL42.2.23.tar.gz does have DriverInfo
I don't remember the details. I probably use git clone:
D:\DEVELOPMENT\PREALPHA\branches\postgresql-jdbc\.git>dir
Volume in drive D is System Reserved
Volume Serial Number is FEF3-860E
Directory of D:\DEVELOPMENT\PREALPHA\branches\postgresql-jdbc\.git
08/03/2021 11:33 PM 130 config
08/03/2021 11:33 PM 73 description
08/03/2021 11:33 PM 23 HEAD
08/03/2021 11:33 PM <DIR> hooks
08/03/2021 11:33 PM <DIR> info
08/03/2021 11:33 PM <DIR> objects
08/03/2021 11:33 PM <DIR> refs
3 File(s) 226 bytes
4 Dir(s) 1,413,844,410,368 bytes free
3) After adding all the missing external libraries (such as jna, waffle, osgi...) it compiled successfully.4) There are run time errors after testing the built library with a small test program:(4.1) If jna and jna-platform are of version 5.0.0 or newer, the following line causes errors because no such a constructor exists:SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, receivedToken);Note: Verson 5.0.0 (or newer) has only one constructor SecBufferDesc().(4.2) If jna and jna-platform are of older version (4.5.2), SecBufferDesc does provide 3 different constructor, but the following code causes errors:Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");This class references SspiUtil$ManagedSecBufferDesc, which is only available from version 5.0.0 of jna-platform (or newer).So basically the implementation of SSPIClient uses different JNA APIs from incompatible versions.Would you please take a look?I can, but if you can provide your test program that would be helpful
The code above is all that I put into the "main" method of the test program.
Any help is very much appreciated!
Dave
Thanks,
Brian Ye
Attachment
On Mon, 16 Aug 2021 at 13:39, Brian Ye <brian.y.ye@gmail.com> wrote:
Hi Dave,Thanks for your reply.Please see my inline responses below.Best regards,Brian YeOn Sat, 7 Aug 2021 at 11:50, Brian Ye <brian.y.ye@gmail.com> wrote:Dear Sirs,I was trying to use postgresql jdbc. The downloaded version did not work for me so I tried to build the project myself using Eclipse (the suggested gradle build method gave me errors).Why did the download version not work? Can you elaborate.Before answering this question, let me give some background information so that we are sure that postgresql with kerberos support works in my Windows environment (using SSPI).I have the PostgreSQL server running as a service:For both IPV4 and IPV6, I configured the login for my account ( briany@CORP) to use SSPI:#ipv4#ipv6host all briany@CORP ::/0 sspiThe SPN was registered:Registered ServicePrincipalNames for CN=Brian Ye,CN=Users,DC=corp,DC=whamtech,DC=com:postgres/by64.corp.whamtech.com:5432Now I use "psql" utility to login using Kerberos:D:\Programs\PostgreSQL\13\data>psql -U briany@CORP -d postgrespsql (13.1)WARNING: Console code page (437) differs from Windows code page (1252)8-bit characters might not work correctly. See psql referencepage "Notes for Windows users" for details.Type "help" for help.postgres=> \dtList of relationsSchema | Name | Type | Owner--------+-------------+-------+----------public | simpletable | table | postgres(1 row)postgres=>So it works.I also configured ODBC using Kerberos, it also worked:I downloaded the jdbc driver (postgresql-42.2.23.jar), and use the following simple test code to connect:try {java.util.Properties info = new java.util.Properties();info.setProperty("user", "postgres"); // LINE ainfo.setProperty("password", "postgres"); // LINE b//info.setProperty("user", "briany@CORP"); // LINE cClass.forName("org.postgresql.Driver");c = DriverManager.getConnection("jdbc:postgresql://by64:5432/", // LINE dinfo);} catch (Exception e) {e.printStackTrace();System.err.println(e.getClass().getName()+": "+e.getMessage());System.exit(0);}It works this way (using password).If I comment oout LINE a and LINE b, uncomment LINE c (to use a different account that requies Kerberos login), running this program produces the following:Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/Win32Exceptionat java.base/java.lang.Class.forName0(Native Method)at java.base/java.lang.Class.forName(Class.java:315)at org.postgresql.core.v3.ConnectionFactoryImpl.createSSPI(ConnectionFactoryImpl.java:82)at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:712)at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:161)at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)at org.postgresql.Driver.makeConnection(Driver.java:465)at org.postgresql.Driver.connect(Driver.java:264)at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)at PostgreSQLJDBC.main(PostgreSQLJDBC.java:21)Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.win32.Win32Exceptionat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)... 13 moreI also downloaded jna, waffle libraries and tried it:D:\Users\briany\test\java\jdbc\PostgreSQLJDBC_sspi>java -cp C:\Users\briany\Downloads\postgresql-42.2.23.jarlC:\users\briany\Downloads\jna-4.5.2.jar;C:\users\briany\Downloads\jna-platform-4.5.2.jar;C:\Users\briany\Downloads\waffle-jna-3.0.jar;. -Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=c:\windows\krb5.ini PostgreSQLJDBCjava.lang.ClassNotFoundException: org.postgresql.Driverat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)at java.base/java.lang.Class.forName0(Native Method)at java.base/java.lang.Class.forName(Class.java:315)at PostgreSQLJDBC.main(PostgreSQLJDBC.java:18)java.lang.ClassNotFoundException: org.postgresql.Driver
Note that the classpath is wrong. you have an l between the postgres jar and the jna jar.
Changing LINE d to"jdbc:postgresql://by64:5432/briany?kerberosServerName=postgres&jaasApplicationName=pgjdbc&user=briany/by64.corp.whamtech.com:5432",resulted in the same error:"D:\Users\briany\test\java\jdbc\PostgreSQLJDBC_sspi>java -cp C:\Users\briany\Downloads\postgresql-42.2.23.jarlC:\users\briany\Downloads\jna-4.5.2.jar;C:\users\briany\Downloads\jna-platform-4.5.2.jar;C:\Users\briany\Downloads\waffle-jna-3.0.jar;. -Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=c:\windows\krb5.ini PostgreSQLJDBCjava.lang.ClassNotFoundException: org.postgresql.Driverat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)at java.base/java.lang.Class.forName0(Native Method)at java.base/java.lang.Class.forName(Class.java:315)at PostgreSQLJDBC.main(PostgreSQLJDBC.java:18)java.lang.ClassNotFoundException: org.postgresql.DriverWhat errors were encountered when you tried to build it?I can finally compile the package after adding the following into the build path, but have the run-time errors as described in the item 4) below.I have encountered several problems:1) Download the source from jdbc.posgresql.org, this source does not have the SSPIClient implementation (it only has the ISSPIClient interface).Interesting. I can confirm that it does not exist. I will rectify this.2) Downloaded the source from github. This version does not have the souce code for org.postgresql.util.DriverInfo.java. I copied it from the downloaded file from step 1) above.https://github.com/pgjdbc/pgjdbc/archive/refs/tags/REL42.2.23.tar.gz does have DriverInfoI don't remember the details. I probably use git clone:D:\DEVELOPMENT\PREALPHA\branches\postgresql-jdbc\.git>dirVolume in drive D is System ReservedVolume Serial Number is FEF3-860EDirectory of D:\DEVELOPMENT\PREALPHA\branches\postgresql-jdbc\.git08/03/2021 11:33 PM 130 config08/03/2021 11:33 PM 73 description08/03/2021 11:33 PM 23 HEAD08/03/2021 11:33 PM <DIR> hooks08/03/2021 11:33 PM <DIR> info08/03/2021 11:33 PM <DIR> objects08/03/2021 11:33 PM <DIR> refs3 File(s) 226 bytes4 Dir(s) 1,413,844,410,368 bytes free3) After adding all the missing external libraries (such as jna, waffle, osgi...) it compiled successfully.4) There are run time errors after testing the built library with a small test program:(4.1) If jna and jna-platform are of version 5.0.0 or newer, the following line causes errors because no such a constructor exists:SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, receivedToken);Note: Verson 5.0.0 (or newer) has only one constructor SecBufferDesc().
Interesting, I will take a look
(4.2) If jna and jna-platform are of older version (4.5.2), SecBufferDesc does provide 3 different constructor, but the following code causes errors:Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");This class references SspiUtil$ManagedSecBufferDesc, which is only available from version 5.0.0 of jna-platform (or newer).So basically the implementation of SSPIClient uses different JNA APIs from incompatible versions.Would you please take a look?I can, but if you can provide your test program that would be helpful
The code above is all that I put into the "main" method of the test program.Any help is very much appreciated!
Thanks,
Dave