You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/10/10 00:02:53 UTC
svn commit: r1396374 - in /commons/proper/net/trunk/src: changes/
main/java/org/apache/commons/net/imap/ main/java/org/apache/commons/net/smtp/
Author: sebb
Date: Tue Oct 9 22:02:52 2012
New Revision: 1396374
URL: http://svn.apache.org/viewvc?rev=1396374&view=rev
Log:
NET-482 Support XOAUTH
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/AuthenticatingIMAPClient.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1396374&r1=1396373&r2=1396374&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Tue Oct 9 22:02:52 2012
@@ -66,6 +66,9 @@ The <action> type attribute can be add,u
This release fixes bugs and adds some new functionality (see below).
It is binary compatible with previous releases
">
+ <action issue="NET-482" dev="sebb" type="update" due-to="Houman Atashbar">
+ Support XOAUTH.
+ </action>
<action issue="NET-484" dev="sebb" type="fix">
Base64.CHUNK_SEPARATOR should be private
</action>
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/AuthenticatingIMAPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/AuthenticatingIMAPClient.java?rev=1396374&r1=1396373&r2=1396374&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/AuthenticatingIMAPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/AuthenticatingIMAPClient.java Tue Oct 9 22:02:52 2012
@@ -197,6 +197,15 @@ public class AuthenticatingIMAPClient ex
}
return result == IMAPReply.OK;
}
+ case XOAUTH:
+ {
+ int result = sendData(new String(username.getBytes()));
+ if (result == IMAPReply.OK)
+ {
+ setState(IMAP.IMAPState.AUTH_STATE);
+ }
+ return result == IMAPReply.OK;
+ }
}
return false; // safety check
}
@@ -231,8 +240,10 @@ public class AuthenticatingIMAPClient ex
/** The standarised (RFC2195) CRAM-MD5 method, which doesn't send the password (secure). */
CRAM_MD5("CRAM-MD5"),
/** The unstandarised Microsoft LOGIN method, which sends the password unencrypted (insecure). */
- LOGIN("LOGIN");
-
+ LOGIN("LOGIN"),
+ /** XOAUTH */
+ XOAUTH("XOAUTH");
+
private final String authName;
private AUTH_METHOD(String name){
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java?rev=1396374&r1=1396373&r2=1396374&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPCommand.java Tue Oct 9 22:02:52 2012
@@ -36,6 +36,8 @@ public enum IMAPCommand
AUTHENTICATE(1),
LOGIN(2),
+ XOAUTH(1),
+
// commands valid in authenticated state
SELECT(1),
EXAMINE(1),
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java?rev=1396374&r1=1396373&r2=1396374&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java Tue Oct 9 22:02:52 2012
@@ -144,7 +144,14 @@ public class AuthenticatingSMTPClient ex
/***
* Authenticate to the SMTP server by sending the AUTH command with the
* selected mechanism, using the given username and the given password.
- * <p>
+ *
+ * @param method the method to use, one of the {@link AuthenticatingSMTPClient.AUTH_METHOD} enum values
+ * @param username the user name.
+ * If the method is XOAUTH, then this is used as the plain text oauth protocol parameter string
+ * which is Base64-encoded for transmission.
+ * @param password the password for the username.
+ * Ignored for XOAUTH.
+ *
* @return True if successfully completed, false if not.
* @exception SMTPConnectionClosedException
* If the SMTP server prematurely closes the connection as a result
@@ -206,6 +213,12 @@ public class AuthenticatingSMTPClient ex
}
return SMTPReply.isPositiveCompletion(sendCommand(
Base64.encodeBase64StringUnChunked(password.getBytes())));
+ }
+ else if (method.equals(AUTH_METHOD.XOAUTH))
+ {
+ return SMTPReply.isPositiveIntermediate(sendCommand(
+ Base64.encodeBase64StringUnChunked(username.getBytes())
+ ));
} else {
return false; // safety check
}
@@ -241,7 +254,9 @@ public class AuthenticatingSMTPClient ex
/** The standarised (RFC2195) CRAM-MD5 method, which doesn't send the password (secure). */
CRAM_MD5,
/** The unstandarised Microsoft LOGIN method, which sends the password unencrypted (insecure). */
- LOGIN;
+ LOGIN,
+ /** XOAuth method which accepts a signed and base64ed OAuth URL. */
+ XOAUTH;
/**
* Gets the name of the given authentication method suitable for the server.
@@ -256,6 +271,8 @@ public class AuthenticatingSMTPClient ex
return "CRAM-MD5";
} else if (method.equals(AUTH_METHOD.LOGIN)) {
return "LOGIN";
+ } else if (method.equals(AUTH_METHOD.XOAUTH)) {
+ return "XOAUTH";
} else {
return null;
}