summaryrefslogtreecommitdiffstats
path: root/gerrit-patch-commonsnet
diff options
context:
space:
mode:
authorBob Foerster <robert@erafx.com>2011-03-10 11:55:11 -0500
committerBob Foerster <robert@erafx.com>2011-03-10 11:55:11 -0500
commita1b2d459a925895bcffc28ac8dfac221bd41438a (patch)
tree2089ada760cc37089ca42b84be7a41d94ac2ca8b /gerrit-patch-commonsnet
parent0ff5ff01121617e4bcdda25e67da46f71dcbc85c (diff)
Add support for SMTP AUTH LOGIN to AuthSMTPClient
AuthSMTPClient only supports CRAM-SHA1, CRAM-MD5, and PLAIN methods of authentication. This change adds support for LOGIN, which is another common SMTP authentication mechanism. Change-Id: Ia03b74c7d121e00a50612e641968ca9ccfb3b5da Signed-off-by: Bob Foerster <robert@erafx.com>
Diffstat (limited to 'gerrit-patch-commonsnet')
-rw-r--r--gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java b/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java
index 4db7de631c..7d7bc49c4c 100644
--- a/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java
+++ b/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java
@@ -103,10 +103,12 @@ public class AuthSMTPClient extends SMTPClient {
if (types.contains("CRAM-MD5")) {
return authCram(smtpUser, smtpPass, "MD5");
}
+ if (types.contains("LOGIN")) {
+ return authLogin(smtpUser, smtpPass);
+ }
if (types.contains("PLAIN")) {
return authPlain(smtpUser, smtpPass);
}
-
throw new IOException("Unsupported AUTH: " + authTypes);
}
@@ -135,6 +137,21 @@ public class AuthSMTPClient extends SMTPClient {
return SMTPReply.isPositiveCompletion(sendCommand(cmd));
}
+ private boolean authLogin(String smtpUser, String smtpPass) throws UnsupportedEncodingException,
+ IOException {
+ if (sendCommand("AUTH", "LOGIN") != 334) {
+ return false;
+ }
+
+ String cmd = encodeBase64(smtpUser.getBytes(UTF_8));
+ if(sendCommand(cmd) != 334) {
+ return false;
+ }
+
+ cmd = encodeBase64(smtpPass.getBytes(UTF_8));
+ return SMTPReply.isPositiveCompletion(sendCommand(cmd));
+ }
+
private static final char[] hexchar =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};