diff options
author | Bruce Momjian | 1997-11-07 21:07:48 +0000 |
---|---|---|
committer | Bruce Momjian | 1997-11-07 21:07:48 +0000 |
commit | 5af43965cf30f4a0844cca384170a44c7acc6176 (patch) | |
tree | a2e523dbe97f7bb221a4db96df6ccc97c05a886c /src/interfaces/jdbc/postgresql/Connection.java | |
parent | c17fa36d3c5f819591707c49fccd991b737a89eb (diff) |
Update of Java driver from Peter Mount.
Diffstat (limited to 'src/interfaces/jdbc/postgresql/Connection.java')
-rw-r--r-- | src/interfaces/jdbc/postgresql/Connection.java | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/interfaces/jdbc/postgresql/Connection.java b/src/interfaces/jdbc/postgresql/Connection.java index e79d1fe953b..09344e1fe08 100644 --- a/src/interfaces/jdbc/postgresql/Connection.java +++ b/src/interfaces/jdbc/postgresql/Connection.java @@ -36,15 +36,20 @@ public class Connection implements java.sql.Connection private String PG_PASSWORD; private String PG_DATABASE; private boolean PG_STATUS; - private boolean PG_AUTH; // true, then password auth used public boolean CONNECTION_OK = true; public boolean CONNECTION_BAD = false; + private static final int STARTUP_LEN = 288; // Length of a startup packet + + // These are defined in src/include/libpq/pqcomm.h private int STARTUP_CODE = STARTUP_USER; private static final int STARTUP_USER = 7; // User auth + private static final int STARTUP_KRB4 = 10; // Kerberos 4 (unused) + private static final int STARTUP_KRB5 = 11; // Kerberos 5 (unused) + private static final int STARTUP_HBA = 12; // Host Based + private static final int STARTUP_NONE = 13; // Unauthenticated (unused) private static final int STARTUP_PASS = 14; // Password auth - private static final int STARTUP_LEN = 288; // Length of a startup packet private boolean autoCommit = true; private boolean readOnly = false; @@ -84,10 +89,22 @@ public class Connection implements java.sql.Connection PG_HOST = new String(host); PG_STATUS = CONNECTION_BAD; - if(info.getProperty("auth") != null) { - PG_AUTH=true; + // This handles the auth property. Any value begining with p enables + // password authentication, while anything begining with i enables + // ident (RFC 1413) authentication. Any other values default to trust. + // + // Also, the postgresql.auth system property can be used to change the + // local default, if the auth property is not present. + // + String auth = info.getProperty("auth",System.getProperty("postgresql.auth","trust")).toLowerCase(); + if(auth.startsWith("p")) { + // Password authentication STARTUP_CODE=STARTUP_PASS; + } else if(auth.startsWith("i")) { + // Ident (RFC 1413) authentication + STARTUP_CODE=STARTUP_HBA; } else { + // Anything else defaults to trust authentication STARTUP_CODE=STARTUP_USER; } @@ -107,7 +124,7 @@ public class Connection implements java.sql.Connection pg_stream.Send(PG_USER.getBytes(), len); // Send the password packet if required - if(PG_AUTH) { + if(STARTUP_CODE == STARTUP_PASS) { len=STARTUP_LEN; pg_stream.SendInteger(len, 4); len -= 4; pg_stream.SendInteger(STARTUP_PASS, 4); len -= 4; |