Re: Are these bugs?

Поиск
Список
Период
Сортировка
От Dave Cramer
Тема Re: Are these bugs?
Дата
Msg-id CADK3HHKjHth+Fa0sohDEnYk3=0-2pD5tnukcmdb8zTabUzHz2A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Are these bugs?  (Brian Ye <brian.y.ye@gmail.com>)
Список pgsql-jdbc


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 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:

image.png

For both IPV4 and IPV6, I configured the login for my account ( briany@CORP) to use SSPI:

#ipv4
host    all             briany@CORP 0.0.0.0/0 sspi

#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:
image.png

image.png


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



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 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.
image.png

 

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.

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().
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

Virus-free. www.avg.com
Вложения

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Brian Ye
Дата:
Сообщение: Re: Are these bugs?
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: defaultRowFetchSize and no known snapshots error