? gss.patch
? gss2.patch
? gss3.patch
Index: build.xml
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/build.xml,v
retrieving revision 1.80
diff -c -r1.80 build.xml
*** build.xml 19 Feb 2008 05:31:48 -0000 1.80
--- build.xml 8 May 2008 06:20:05 -0000
***************
*** 78,83 ****
--- 78,84 ----
+
***************
*** 186,191 ****
--- 187,195 ----
+
+
+
***************
*** 319,324 ****
--- 323,337 ----
+
+
+
+
+
+
+
+
+
***************
*** 329,334 ****
--- 342,348 ----
+
Index: org/postgresql/Driver.java.in
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/Driver.java.in,v
retrieving revision 1.73
diff -c -r1.73 Driver.java.in
*** org/postgresql/Driver.java.in 13 Apr 2008 16:03:49 -0000 1.73
--- org/postgresql/Driver.java.in 8 May 2008 06:20:06 -0000
***************
*** 117,122 ****
--- 117,129 ----
private Properties loadDefaultProperties() throws IOException {
Properties merged = new Properties();
+ try {
+ merged.setProperty("user", System.getProperty("user.name"));
+ } catch (java.lang.SecurityException se) {
+ // We're just trying to set a default, so if we can't
+ // it's not a big deal.
+ }
+
// If we are loaded by the bootstrap classloader, getClassLoader()
// may return null. In that case, try to fall back to the system
// classloader.
***************
*** 773,776 ****
--- 780,793 ----
return l_return;
}
+ public static void makeGSS(org.postgresql.core.PGStream stream, String host, String user, String password, Logger logger) throws IOException, SQLException {
+ @GSS@ org.postgresql.gss.MakeGSS.authenticate(stream, host, user, password, logger);
+ }
+
+ public static boolean gssEnabled() {
+ boolean l_return = false;
+ @GSS@ l_return = true;
+ return l_return;
+ }
+
}
Index: org/postgresql/core/v3/ConnectionFactoryImpl.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/core/v3/ConnectionFactoryImpl.java,v
retrieving revision 1.16
diff -c -r1.16 ConnectionFactoryImpl.java
*** org/postgresql/core/v3/ConnectionFactoryImpl.java 13 Apr 2008 16:03:50 -0000 1.16
--- org/postgresql/core/v3/ConnectionFactoryImpl.java 8 May 2008 06:20:06 -0000
***************
*** 39,44 ****
--- 39,47 ----
private static final int AUTH_REQ_CRYPT = 4;
private static final int AUTH_REQ_MD5 = 5;
private static final int AUTH_REQ_SCM = 6;
+ private static final int AUTH_REQ_GSS = 7;
+ private static final int AUTH_REQ_GSS_CONTINUE = 8;
+ private static final int AUTH_REQ_SSPI = 9;
/** Marker exception; thrown when we want to fall back to using V2. */
private static class UnsupportedProtocolException extends IOException {
***************
*** 98,104 ****
sendStartupPacket(newStream, params, logger);
// Do authentication (until AuthenticationOk).
! doAuthentication(newStream, user, info.getProperty("password"), logger);
// Do final startup.
ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, info, logger);
--- 101,107 ----
sendStartupPacket(newStream, params, logger);
// Do authentication (until AuthenticationOk).
! doAuthentication(newStream, host, user, info.getProperty("password"), logger);
// Do final startup.
ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, info, logger);
***************
*** 250,256 ****
pgStream.flush();
}
! private void doAuthentication(PGStream pgStream, String user, String password, Logger logger) throws IOException, SQLException
{
// Now get the response from the backend, either an error message
// or an authentication request
--- 253,259 ----
pgStream.flush();
}
! private void doAuthentication(PGStream pgStream, String host, String user, String password, Logger logger) throws IOException, SQLException
{
// Now get the response from the backend, either an error message
// or an authentication request
***************
*** 369,374 ****
--- 372,385 ----
break;
}
+ case AUTH_REQ_GSS:
+ if (!Driver.gssEnabled())
+ throw new PSQLException(GT.tr("The driver does not support GSSAPI authentication."), PSQLState.CONNECTION_FAILURE);
+
+ Driver.makeGSS(pgStream, host, user, password, logger);
+ break;
+
+
case AUTH_REQ_OK:
if (logger.logDebug())
logger.debug(" <=BE AuthenticationOk");
Index: org/postgresql/gss/GSSCallbackHandler.java
===================================================================
RCS file: org/postgresql/gss/GSSCallbackHandler.java
diff -N org/postgresql/gss/GSSCallbackHandler.java
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- org/postgresql/gss/GSSCallbackHandler.java 8 May 2008 06:20:06 -0000
***************
*** 0 ****
--- 1,49 ----
+ package org.postgresql.gss;
+
+ import java.io.IOException;
+ import javax.security.auth.callback.*;
+
+ public class GSSCallbackHandler implements CallbackHandler {
+
+ private final String user;
+ private final String password;
+
+ public GSSCallbackHandler(String user, String password)
+ {
+ this.user = user;
+ this.password = password;
+ }
+
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
+ {
+ for (int i=0; i Password(GSS Authentication Token)");
+
+ pgStream.SendChar('p');
+ pgStream.SendInteger4(4 + outToken.length);
+ pgStream.Send(outToken);
+ pgStream.flush();
+ }
+
+ if (!secContext.isEstablished()) {
+ int response = pgStream.ReceiveChar();
+ // Error
+ if (response == 'E') {
+ int l_elen = pgStream.ReceiveInteger4();
+ ServerErrorMessage l_errorMsg = new ServerErrorMessage(pgStream.ReceiveString(l_elen - 4), logger.getLogLevel());
+
+ if (logger.logDebug())
+ logger.debug(" <=BE ErrorMessage(" + l_errorMsg + ")");
+
+ return new PSQLException(l_errorMsg);
+
+ } else if (response == 'R') {
+
+ if (logger.logDebug())
+ logger.debug(" <=BE AuthenticationGSSContinue");
+
+ int len = pgStream.ReceiveInteger4();
+ int type = pgStream.ReceiveInteger4();
+ // KJJ check type = 8
+ inToken = pgStream.Receive(len - 8);
+ } else {
+ // Unknown/unexpected message type.
+ return new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+ }
+ } else {
+ established = true;
+ }
+ }
+
+ } catch (IOException e) {
+ return e;
+ } catch (GSSException gsse) {
+ return new PSQLException(GT.tr("GSS Authentication failed"), PSQLState.CONNECTION_FAILURE, gsse);
+ }
+
+ return null;
+ }
+ }
+