commits@javamail.java.net

[mercurial:102] Fix Novell GroupWise XGWTRUSTEDAPP support to issue LOGIN after AUTHENTI

From: <shannon_at_kenai.com>
Date: Mon, 9 Feb 2009 19:40:56 +0000 (GMT)

Repository: mercurial
Revision: 102
Author: Bill Shannon <bill.shannon_at_sun.com>
Date: 2009-01-30 21:16:24 UTC

Log Message:
-----------
Fix Novell GroupWise XGWTRUSTEDAPP support to issue LOGIN after
AUTHENTICATE.

Modified Paths:
--------------
   
mail/src/main/java/com/sun/mail/imap/protocol/IMAPSaslAuthenticator.jav
a

Diffs:
-----
diff -r 68c5b6d7a3f2 -r 2cdf27dc90df
mail/src/main/java/com/sun/mail/imap/protocol/IMAPSaslAuthenticator.jav
a
---
a/mail/src/main/java/com/sun/mail/imap/protocol/IMAPSaslAuthenticator.j
ava  Mon Jan 26 11:10:08 2009 -0800
+++
b/mail/src/main/java/com/sun/mail/imap/protocol/IMAPSaslAuthenticator.j
ava  Fri Jan 30 13:16:24 2009 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the
GNU
  * General Public License Version 2 only ("GPL") or the Common
Development
@@ -70,8 +70,9 @@
	this.host = host;
     }
 
-    public boolean authenticate(String[] mechs, String realm, String
authzid,
-				String u, String p) throws
ProtocolException {
+    public boolean authenticate(String[] mechs, final String realm,
+				final String authzid, final String u,
+				final String p) throws
ProtocolException {
 
	synchronized (pr) {	// authenticate method should be
synchronized
	Vector v = new Vector();
@@ -86,9 +87,6 @@
	}
 
	SaslClient sc;
-	final String r0 = realm;
-	final String u0 = u;
-	final String p0 = p;
	CallbackHandler cbh = new CallbackHandler() {
	    public void handle(Callback[] callbacks) {
		if (debug)
@@ -100,24 +98,24 @@
							callbacks[i]);
		    if (callbacks[i] instanceof NameCallback) {
			NameCallback ncb = (NameCallback)callbacks[i];
-			ncb.setName(u0);
+			ncb.setName(u);
		    } else if (callbacks[i] instanceof
PasswordCallback) {
			PasswordCallback pcb =
(PasswordCallback)callbacks[i];
-			pcb.setPassword(p0.toCharArray());
+			pcb.setPassword(p.toCharArray());
		    } else if (callbacks[i] instanceof RealmCallback) {
			RealmCallback rcb =
(RealmCallback)callbacks[i];
-			rcb.setText(r0 != null ?
-			    r0 : rcb.getDefaultText());
+			rcb.setText(realm != null ?
+				    realm : rcb.getDefaultText());
		    } else if (callbacks[i] instanceof
RealmChoiceCallback) {
			RealmChoiceCallback rcb =
			    (RealmChoiceCallback)callbacks[i];
-			if (r0 == null)
+			if (realm == null)
			   
rcb.setSelectedIndex(rcb.getDefaultChoice());
			else {
			    // need to find specified realm in list
			    String[] choices = rcb.getChoices();
			    for (int k = 0; k < choices.length; k++) {
-				if (choices[k].equals(r0)) {
+				if (choices[k].equals(realm)) {
				    rcb.setSelectedIndex(k);
				    break;
				}
@@ -254,6 +252,26 @@
	// Handle the final OK, NO, BAD or BYE response
	pr.handleResult(r);
	pr.setCapabilities(r);
+
+	/*
+	 * If we're using the Novell Groupwise XGWTRUSTEDAPP mechanism
+	 * we always have to issue a LOGIN command to select the user
+	 * we want to operate as.
+	 */
+	if (isXGWTRUSTEDAPP) {
+	    Argument args = new Argument();
+	    args.writeString(authzid != null ? authzid : u);
+
+	    responses = pr.command("LOGIN", args);
+
+	    // dispatch untagged responses
+	    pr.notifyResponseHandlers(responses);
+
+	    // Handle result of this command
+	    pr.handleResult(responses[responses.length-1]);
+	    // If the response includes a CAPABILITY response code,
process it
+	    pr.setCapabilities(responses[responses.length-1]);
+	}
	return true;
     }
     }