pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Support waffle>1.7.4
8+ messages / 3 participants
[nested] [flat]

* Support waffle>1.7.4
@ 2016-04-12 17:51  Christian Ullrich <chris@chrullrich.net>
  0 siblings, 1 reply; 8+ messages in thread

From: Christian Ullrich @ 2016-04-12 17:51 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

while lately discussion has mostly been about how to exclude waffle from 
the non-Windows build, I would like to request an update in the other 
direction. Last November, waffle-jna 1.7.5 was released, containing an 
incompatible API change that is also present in all released 1.8 
versions. The fix is simple; as far as the code goes, it is a one-line 
patch. What incantations may be required on the Maven side, I do not know.

The API change was made as part of fixing a handle leak [1].

Applying this patch raises the minimum required waffle version to 1.7.5 
or 1.8.0.

Thank you.

[1] <https://github.com/dblock/waffle/pull/239;

-- 
Christian

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Attachments:

0001-Track-API-change-in-Waffle-1.7.4.patch (text/plain, 1.1K) download From 4a3bee8187ce71baaf3f7fdf2fff3b0d4a5c2677 Mon Sep 17 00:00:00 2001 From: Christian Ullrich <chris@chrullrich.net> Date: Tue, 12 Apr 2016 19:43:09 +0200 Subject: [PATCH] Track API change in Waffle > 1.7.4. --- pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java b/pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java index de92a2d..74870eb 100644 --- a/pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java +++ b/pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java @@ -160,7 +160,7 @@ public class SSPIClient { sspiContext = new WindowsSecurityContextImpl(); sspiContext.setPrincipalName(targetName); - sspiContext.setCredentialsHandle(clientCredentials.getHandle()); + sspiContext.setCredentialsHandle(clientCredentials); sspiContext.setSecurityPackage(securityPackage); sspiContext.initialize(null, null, targetName); } catch (Win32Exception ex) { -- 2.7.0.windows.1
^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: Support waffle>1.7.4
@ 2016-04-17 12:18  Craig Ringer <craig@2ndquadrant.com>
  parent: Christian Ullrich <chris@chrullrich.net>
  0 siblings, 1 reply; 8+ messages in thread

From: Craig Ringer @ 2016-04-17 12:18 UTC (permalink / raw)
  To: Christian Ullrich <chris@chrullrich.net>; +Cc: pgsql-jdbc

On 13 April 2016 at 01:51, Christian Ullrich <chris@chrullrich.net> wrote:

> Hello,
>
> while lately discussion has mostly been about how to exclude waffle from
> the non-Windows build, I would like to request an update in the other
> direction. Last November, waffle-jna 1.7.5 was released, containing an
> incompatible API change that is also present in all released 1.8 versions.
> The fix is simple; as far as the code goes, it is a one-line patch. What
> incantations may be required on the Maven side, I do not know.
>
> The API change was made as part of fixing a handle leak [1].
>
> Applying this patch raises the minimum required waffle version to 1.7.5 or
> 1.8.0.
>
>
Looks sensible to me, it just requires a pom.xml update to bump the
required waffle version along with it.

I'm on hols this week but will try to get it sorted out next week.
Christian, if you send a github pull that passes tests and updates the
pom.xml I'll just merge it directly instead.

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Support waffle>1.7.4
@ 2016-04-17 20:16  Christian Ullrich <chris@chrullrich.net>
  parent: Craig Ringer <craig@2ndquadrant.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Christian Ullrich @ 2016-04-17 20:16 UTC (permalink / raw)
  To: Craig Ringer <craig@2ndquadrant.com>; +Cc: pgsql-jdbc

* Craig Ringer wrote:

> On 13 April 2016 at 01:51, Christian Ullrich <chris@chrullrich.net
> <mailto:chris@chrullrich.net>> wrote:

>     other direction. Last November, waffle-jna 1.7.5 was released,
>     containing an incompatible API change that is also present in all
>     released 1.8 versions. The fix is simple; as far as the code goes,
>     it is a one-line patch. What incantations may be required on the
>     Maven side, I do not know.
>
>     The API change was made as part of fixing a handle leak [1].
>
>     Applying this patch raises the minimum required waffle version to
>     1.7.5 or 1.8.0.
>
> Looks sensible to me, it just requires a pom.xml update to bump the
> required waffle version along with it.
>
> I'm on hols this week but will try to get it sorted out next week.
> Christian, if you send a github pull that passes tests and updates the
> pom.xml I'll just merge it directly instead.

Sorry. I'd be happy to do *that*, but it looks like that's not all there 
is to it. It would be easy if the waffle version was set in pgjdbc's 
pom.xml itself, but instead it references a property from the parent 
(pgjdbc-versions, or possibly pgjdbc-core-parent, because apparently you 
have to change it in both places before the build actually starts caring).

My current theory is that I'd have to somehow remove the property from 
-core-parent (for reasons of sanity), then change it in -versions, bump 
the version of -versions itself, track that change in -core-parent, put 
both in the local Maven repository to fake a release, then update the 
version of -versions referenced in pgjdbc so it picks them up, massage 
the environment until the tests actually pass, and then send three pull 
requests, against three repositories, to effectively remove 12 bytes and 
change one more; three pull requests, of course, the merging of each of 
which individually breaks the build. (</sentence>)

The alternative: Do nothing for a week.

I think I'll pick the second one, thank you.

-- 
Christian



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Support waffle>1.7.4
@ 2016-04-17 22:45  Dave Cramer <pg@fastcrypt.com>
  parent: Christian Ullrich <chris@chrullrich.net>
  1 sibling, 0 replies; 8+ messages in thread

From: Dave Cramer @ 2016-04-17 22:45 UTC (permalink / raw)
  To: Christian Ullrich <chris@chrullrich.net>; +Cc: Craig Ringer <craig@2ndquadrant.com>; pgsql-jdbc

On 17 April 2016 at 16:16, Christian Ullrich <chris@chrullrich.net> wrote:

> * Craig Ringer wrote:
>
> On 13 April 2016 at 01:51, Christian Ullrich <chris@chrullrich.net
>> <mailto:chris@chrullrich.net>> wrote:
>>
>
>     other direction. Last November, waffle-jna 1.7.5 was released,
>>     containing an incompatible API change that is also present in all
>>     released 1.8 versions. The fix is simple; as far as the code goes,
>>     it is a one-line patch. What incantations may be required on the
>>     Maven side, I do not know.
>>
>>     The API change was made as part of fixing a handle leak [1].
>>
>>     Applying this patch raises the minimum required waffle version to
>>     1.7.5 or 1.8.0.
>>
>> Looks sensible to me, it just requires a pom.xml update to bump the
>> required waffle version along with it.
>>
>> I'm on hols this week but will try to get it sorted out next week.
>> Christian, if you send a github pull that passes tests and updates the
>> pom.xml I'll just merge it directly instead.
>>
>
> Sorry. I'd be happy to do *that*, but it looks like that's not all there
> is to it. It would be easy if the waffle version was set in pgjdbc's
> pom.xml itself, but instead it references a property from the parent
> (pgjdbc-versions, or possibly pgjdbc-core-parent, because apparently you
> have to change it in both places before the build actually starts caring).
>
> My current theory is that I'd have to somehow remove the property from
> -core-parent (for reasons of sanity), then change it in -versions, bump the
> version of -versions itself, track that change in -core-parent, put both in
> the local Maven repository to fake a release, then update the version of
> -versions referenced in pgjdbc so it picks them up, massage the environment
> until the tests actually pass, and then send three pull requests, against
> three repositories, to effectively remove 12 bytes and change one more;
> three pull requests, of course, the merging of each of which individually
> breaks the build. (</sentence>)
>
> The alternative: Do nothing for a week.
>
> I think I'll pick the second one, thank you.
>
>
> So the reason this is so complicated is that we build for 3 different JRE
versions.



Dave Cramer

davec@postgresintl.com
www.postgresintl.com

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Support waffle>1.7.4
@ 2016-05-09 17:03  Christian Ullrich <chris@chrullrich.net>
  parent: Christian Ullrich <chris@chrullrich.net>
  1 sibling, 1 reply; 8+ messages in thread

From: Christian Ullrich @ 2016-05-09 17:03 UTC (permalink / raw)
  To: Craig Ringer <craig@2ndquadrant.com>; +Cc: pgsql-jdbc

* Christian Ullrich wrote:

> * Craig Ringer wrote:

>> On 13 April 2016 at 01:51, Christian Ullrich <chris@chrullrich.net
>> <mailto:chris@chrullrich.net>> wrote:

>>     other direction. Last November, waffle-jna 1.7.5 was released,
>>     containing an incompatible API change that is also present in all
>>     released 1.8 versions. The fix is simple; as far as the code goes,

>> I'm on hols this week but will try to get it sorted out next week.
>> Christian, if you send a github pull that passes tests and updates the
>> pom.xml I'll just merge it directly instead.

> Sorry. I'd be happy to do *that*, but it looks like that's not all there
> is to it. It would be easy if the waffle version was set in pgjdbc's

I did it myself after all; I hope the result looks somewhat sensible.

- https://github.com/pgjdbc/pgjdbc-parent-poms/pull/5
- https://github.com/pgjdbc/pgjdbc/pull/555

As for "that passes tests", achieving this was not difficult (other than 
getting them to work at all, see my previous PRs from today) because 
there are exactly zero tests for SSPI auth, or at least that is how many 
I could find. What there is, passes.

I thought about writing a few, and I may yet get around to that, but 
then I collided head-on with Maven and had to sedate the Java part of my 
brain.

-- 
Christian



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Support waffle>1.7.4
@ 2016-05-09 23:49  Christian Ullrich <chris@chrullrich.net>
  parent: Christian Ullrich <chris@chrullrich.net>
  0 siblings, 1 reply; 8+ messages in thread

From: Christian Ullrich @ 2016-05-09 23:49 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Craig Ringer <craig@2ndquadrant.com>

* Christian Ullrich wrote:

> I thought about writing a few [SSPI tests], and I may yet get around
 > to that,

Attached is a proposed patch; I cannot send it as a PR because it is 
dependent on Pavel Raiskup's as yet unmerged #546. The Waffle-free build 
option is clearly coming, and there is little point in having SSPI tests 
that then cannot be turned off.

Some explanations:

- Both successful and unsuccessful authentication is tested, the latter
   to ensure that a configuration mistake (such as a "trust" line left
   in pg_hba.conf) has not caused *both* tests to succeed when they
   should have failed.

- Setting up to run these tests is not entirely (or at all) trivial; it
   requires running the database server as an account that is capable of
   SSPI authentication (such as a virtual service account, e.g.
   "NT SERVICE\PostgreSQL") on both domain member and non-member
   systems, or a domain user account.

- Additionally, both pg_hba.conf and, in most cases, pg_ident.conf must
   be configured. In particular, the user account that runs the tests
   must be permitted to authenticate as the database role configured in
   build.properties.

- The tests are not run when Waffle is disabled. I would have preferred
   to have a separate option to turn them off even when building with
   Waffle because the setup is so difficult. I could not think of a way
   to make Maven do this, mostly because profiles cannot be chained, and
   profile activation cannot use two variables, for example
   (!enableWaffle || disableSSPITests).

- There is an intermittent problem where testUnauthorized() fails
   because it gets the wrong exception: It expects SQLSTATE 28000 from
   the server, but sometimes it gets 08001 generated internally in the
   driver. No idea what causes that. I did not want to blindly accept any
   error as proof of failed authentication.

-- 
Christian

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Attachments:

sspi-test.patch (text/plain, 5.5K) download diff --git a/build.properties b/build.properties index e23f96a..14c0e9e 100644 --- a/build.properties +++ b/build.properties @@ -9,6 +9,7 @@ username=test password=test privilegedUser=postgres privilegedPassword= +sspiusername=testsspi preparethreshold=5 loglevel=0 protocolVersion=0 diff --git a/pgjdbc/pom.xml b/pgjdbc/pom.xml index dab5308..2e5ab56 100644 --- a/pgjdbc/pom.xml +++ b/pgjdbc/pom.xml @@ -133,6 +133,9 @@ <exclude>org/postgresql/sspi/NTDSAPIWrapper.java</exclude> <exclude>org/postgresql/sspi/SSPIClient.java</exclude> </excludes> + <testExcludes> + <exclude>org/postgresql/test/sspi/*.java</exclude> + </testExcludes> </configuration> </plugin> </plugins> diff --git a/pgjdbc/src/main/java/org/postgresql/util/PSQLState.java b/pgjdbc/src/main/java/org/postgresql/util/PSQLState.java index 21bfc82..3b40229 100644 --- a/pgjdbc/src/main/java/org/postgresql/util/PSQLState.java +++ b/pgjdbc/src/main/java/org/postgresql/util/PSQLState.java @@ -91,6 +91,7 @@ public class PSQLState implements java.io.Serializable { public final static PSQLState TRANSACTION_STATE_INVALID = new PSQLState("25000"); public final static PSQLState ACTIVE_SQL_TRANSACTION = new PSQLState("25001"); public final static PSQLState NO_ACTIVE_SQL_TRANSACTION = new PSQLState("25P01"); + public final static PSQLState INVALID_AUTHORIZATION_SPECIFICATION = new PSQLState("28000"); public final static PSQLState STATEMENT_NOT_ALLOWED_IN_FUNCTION_CALL = new PSQLState("2F003"); diff --git a/pgjdbc/src/test/java/org/postgresql/test/TestUtil.java b/pgjdbc/src/test/java/org/postgresql/test/TestUtil.java index 2e12cc8..417be9c 100644 --- a/pgjdbc/src/test/java/org/postgresql/test/TestUtil.java +++ b/pgjdbc/src/test/java/org/postgresql/test/TestUtil.java @@ -121,6 +121,13 @@ public class TestUtil { } /* + * Returns the user for SSPI authentication tests + */ + public static String getSSPIUser() { + return System.getProperty("sspiusername"); + } + + /* * postgres like user */ public static String getPrivilegedUser() { @@ -266,7 +273,11 @@ public class TestUtil { public static java.sql.Connection openDB(Properties props) throws Exception { initDriver(); - String user = getUser(); + // Allow properties to override the user name. + String user = props.getProperty("username"); + if (user == null) { + user = getUser(); + } if (user == null) { throw new IllegalArgumentException( "user name is not specified. Please specify 'username' property via -D or build.properties"); diff --git a/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITest.java b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITest.java new file mode 100644 index 0000000..9940fe2 --- /dev/null +++ b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITest.java @@ -0,0 +1,53 @@ +package org.postgresql.test.sspi; + +import org.postgresql.test.TestUtil; +import org.postgresql.util.PSQLException; +import org.postgresql.util.PSQLState; + +import junit.framework.TestCase; + +import java.sql.Connection; +import java.sql.Statement; +import java.util.Properties; + +/* + * These tests require a working SSPI authentication setup + * in the database server that allows the executing user + * to authenticate as the "sspiusername" in the build + * configuration. + */ +public class SSPITest extends TestCase { + + /* + * Tests that SSPI login succeeds and a query can be run. + */ + public void testAuthorized() throws Exception { + Properties props = new Properties(); + props.setProperty("username", TestUtil.getSSPIUser()); + Connection con = TestUtil.openDB(props); + + Statement stmt = con.createStatement(); + stmt.executeQuery("SELECT 1"); + + TestUtil.closeDB(con); + } + + /* + * Tests that SSPI login fails with an unknown/unauthorized + * user name. + */ + public void testUnauthorized() throws Exception { + Properties props = new Properties(); + props.setProperty("username", "invalid" + TestUtil.getSSPIUser()); + + try { + Connection con = TestUtil.openDB(props); + TestUtil.closeDB(con); + fail("Expected a PSQLException"); + } catch (PSQLException e) { + assertEquals(PSQLState.INVALID_AUTHORIZATION_SPECIFICATION.getState(), e.getSQLState()); + } + } + +} + diff --git a/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITestSuite.java b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITestSuite.java new file mode 100644 index 0000000..6f4c706 --- /dev/null +++ b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITestSuite.java @@ -0,0 +1,33 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2014, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- +*/ + +package org.postgresql.test.sspi; + +import junit.framework.JUnit4TestAdapter; +import junit.framework.TestSuite; + +/* + * Executes all known tests for SSPI and includes some utility methods. + */ +public class SSPITestSuite extends TestSuite { + + /* + * The main entry point for JUnit + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite(); + + // + // Add one line per class in our test cases. These should be in order of + // complexity. + suite.addTestSuite(SSPITest.class); + + // That's all folks + return suite; + } +}
^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: Support waffle>1.7.4
@ 2016-05-10 00:34  Dave Cramer <pg@fastcrypt.com>
  parent: Christian Ullrich <chris@chrullrich.net>
  0 siblings, 1 reply; 8+ messages in thread

From: Dave Cramer @ 2016-05-10 00:34 UTC (permalink / raw)
  To: Christian Ullrich <chris@chrullrich.net>; +Cc: pgsql-jdbc; Craig Ringer <craig@2ndquadrant.com>

Ok, I just pushed pavel's PR,

Thanks for this Christian!

Dave Cramer

davec@postgresintl.com
www.postgresintl.com

On 9 May 2016 at 19:49, Christian Ullrich <chris@chrullrich.net> wrote:

> * Christian Ullrich wrote:
>
> I thought about writing a few [SSPI tests], and I may yet get around
>>
> > to that,
>
> Attached is a proposed patch; I cannot send it as a PR because it is
> dependent on Pavel Raiskup's as yet unmerged #546. The Waffle-free build
> option is clearly coming, and there is little point in having SSPI tests
> that then cannot be turned off.
>
> Some explanations:
>
> - Both successful and unsuccessful authentication is tested, the latter
>   to ensure that a configuration mistake (such as a "trust" line left
>   in pg_hba.conf) has not caused *both* tests to succeed when they
>   should have failed.
>
> - Setting up to run these tests is not entirely (or at all) trivial; it
>   requires running the database server as an account that is capable of
>   SSPI authentication (such as a virtual service account, e.g.
>   "NT SERVICE\PostgreSQL") on both domain member and non-member
>   systems, or a domain user account.
>
> - Additionally, both pg_hba.conf and, in most cases, pg_ident.conf must
>   be configured. In particular, the user account that runs the tests
>   must be permitted to authenticate as the database role configured in
>   build.properties.
>
> - The tests are not run when Waffle is disabled. I would have preferred
>   to have a separate option to turn them off even when building with
>   Waffle because the setup is so difficult. I could not think of a way
>   to make Maven do this, mostly because profiles cannot be chained, and
>   profile activation cannot use two variables, for example
>   (!enableWaffle || disableSSPITests).
>
> - There is an intermittent problem where testUnauthorized() fails
>   because it gets the wrong exception: It expects SQLSTATE 28000 from
>   the server, but sometimes it gets 08001 generated internally in the
>   driver. No idea what causes that. I did not want to blindly accept any
>   error as proof of failed authentication.
>
> --
> Christian
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Support waffle>1.7.4
@ 2016-05-10 00:54  Christian Ullrich <chris@chrullrich.net>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Christian Ullrich @ 2016-05-10 00:54 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc; Craig Ringer <craig@2ndquadrant.com>

* Dave Cramer wrote:

> Ok, I just pushed pavel's PR,

Wow, that's a quick turnaround.

PR #557.

-- 
Christian




-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2016-05-10 00:54 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-04-12 17:51 Support waffle>1.7.4 Christian Ullrich <chris@chrullrich.net>
2016-04-17 12:18 ` Craig Ringer <craig@2ndquadrant.com>
2016-04-17 20:16   ` Christian Ullrich <chris@chrullrich.net>
2016-04-17 22:45     ` Dave Cramer <pg@fastcrypt.com>
2016-05-09 17:03     ` Christian Ullrich <chris@chrullrich.net>
2016-05-09 23:49       ` Christian Ullrich <chris@chrullrich.net>
2016-05-10 00:34         ` Dave Cramer <pg@fastcrypt.com>
2016-05-10 00:54           ` Christian Ullrich <chris@chrullrich.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox