| From: | Dave Cramer <davecramer(at)postgres(dot)rocks> |
|---|---|
| To: | Brian Ye <brian(dot)y(dot)ye(at)gmail(dot)com> |
| Cc: | List <pgsql-jdbc(at)postgresql(dot)org> |
| Subject: | Re: Are these bugs? |
| Date: | 2021-08-17 10:13:37 |
| Message-ID: | CADK3HHKjHth+Fa0sohDEnYk3=0-2pD5tnukcmdb8zTabUzHz2A@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
On Mon, 16 Aug 2021 at 13:39, Brian Ye <brian(dot)y(dot)ye(at)gmail(dot)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(dot)y(dot)ye(at)gmail(dot)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: image.png]
>
> For both IPV4 and IPV6, I configured the login for my account ( briany(at)CORP)
> to use SSPI:
>
> #ipv4
> host all briany(at)CORP 0.0.0.0/0 sspi
>
> #ipv6
> host all briany(at)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(at)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: image.png]
>
> [image: 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(at)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: 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.
>>>
>> 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().
>>>
>> 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
>
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dave Cramer | 2021-08-17 17:24:19 | Re: defaultRowFetchSize and no known snapshots error |
| Previous Message | Brian Ye | 2021-08-16 17:39:33 | Re: Are these bugs? |