@@ -36,22 +36,26 @@ private SessionUtil(String dbAddr) {
3636 if (dbAddr != null ) {
3737 // Most drivers expect the user in a connection to be specified like:
3838 // postgresql://<user>@host:port/db
39- // but the PGJDBC expects the user as a parameter like:
40- // postgresql://host:port/db?user=<user>
41- Pattern p = Pattern .compile ("postgresql://((\\ w+)@).*" );
39+ // but the PGJDBC driver expects the user as a parameter like:
40+ // postgresql://host:port/db
41+ // with the username and password passed as separate properties.
42+ Pattern p = Pattern .compile ("postgresql://((\\ w+)(:(\\ w+))?@).*" );
4243 Matcher m = p .matcher (dbAddr );
4344 if (m .matches ()) {
4445 String userPart = m .group (1 );
4546 String user = m .group (2 );
47+ String password = m .group (4 );
4648
47-
48- String sep = "?" ;
49- if (dbAddr . contains ( "? " )) {
50- sep = "&" ;
49+ dbAddr = dbAddr . replace ( userPart , "" );
50+ configuration . setProperty ( "hibernate.connection.user" , user ) ;
51+ if (password != null && ! password . equals ( " " )) {
52+ configuration . setProperty ( "hibernate.connection.password" , password ) ;
5153 }
52- dbAddr = String .format ("%s%suser=%s" , dbAddr .replace (userPart , "" ), sep , user );
5354 }
5455
56+ // The client cert must be in PKCS8 format for Java.
57+ dbAddr = dbAddr .replace ("client.root.key" , "client.root.key.pk8" );
58+
5559 // Add the "jdbc:" prefix to the address and replace in configuration.
5660 dbAddr = "jdbc:" + dbAddr ;
5761 configuration .setProperty ("hibernate.connection.url" , dbAddr );
0 commit comments