From 539f652443694008a9a558faf2a8aefc2d9a46e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Niess?= Date: Tue, 9 Feb 2010 12:40:11 +0000 Subject: [PATCH] SMACK-282: Support SASL-related error conditions git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11616 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smack/PacketReader.java | 2 +- .../smack/SASLAuthentication.java | 44 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index ca075e991..ac8508a2f 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -286,7 +286,7 @@ class PacketReader { // depending on the number of retries final Failure failure = PacketParserUtils.parseSASLFailure(parser); processPacket(failure); - connection.getSASLAuthentication().authenticationFailed(); + connection.getSASLAuthentication().authenticationFailed(failure.getCondition()); } } else if (parser.getName().equals("challenge")) { diff --git a/source/org/jivesoftware/smack/SASLAuthentication.java b/source/org/jivesoftware/smack/SASLAuthentication.java index a7487878b..725230a30 100644 --- a/source/org/jivesoftware/smack/SASLAuthentication.java +++ b/source/org/jivesoftware/smack/SASLAuthentication.java @@ -80,6 +80,10 @@ public class SASLAuthentication implements UserAuthentication { private boolean saslFailed; private boolean resourceBinded; private boolean sessionSupported; + /** + * The SASL related error condition if there was one provided by the server. + */ + private String errorCondition; static { @@ -247,8 +251,14 @@ public class SASLAuthentication implements UserAuthentication { if (saslFailed) { // SASL authentication failed and the server may have closed the connection // so throw an exception - throw new XMPPException("SASL authentication failed using mechanism " + - selectedMechanism); + if (errorCondition != null) { + throw new XMPPException("SASL authentication " + + selectedMechanism + " failed: " + errorCondition); + } + else { + throw new XMPPException("SASL authentication failed using mechanism " + + selectedMechanism); + } } if (saslNegotiated) { @@ -323,8 +333,14 @@ public class SASLAuthentication implements UserAuthentication { if (saslFailed) { // SASL authentication failed and the server may have closed the connection // so throw an exception - throw new XMPPException("SASL authentication failed using mechanism " + - selectedMechanism); + if (errorCondition != null) { + throw new XMPPException("SASL authentication " + + selectedMechanism + " failed: " + errorCondition); + } + else { + throw new XMPPException("SASL authentication failed using mechanism " + + selectedMechanism); + } } if (saslNegotiated) { @@ -384,7 +400,12 @@ public class SASLAuthentication implements UserAuthentication { if (saslFailed) { // SASL authentication failed and the server may have closed the connection // so throw an exception - throw new XMPPException("SASL authentication failed"); + if (errorCondition != null) { + throw new XMPPException("SASL authentication failed: " + errorCondition); + } + else { + throw new XMPPException("SASL authentication failed"); + } } if (saslNegotiated) { @@ -508,10 +529,23 @@ public class SASLAuthentication implements UserAuthentication { /** * Notification message saying that SASL authentication has failed. The server may have * closed the connection depending on the number of possible retries. + * + * @deprecated replaced by {@see #authenticationFailed(String)}. */ void authenticationFailed() { + authenticationFailed(null); + } + + /** + * Notification message saying that SASL authentication has failed. The server may have + * closed the connection depending on the number of possible retries. + * + * @param condition the error condition provided by the server. + */ + void authenticationFailed(String condition) { synchronized (this) { saslFailed = true; + errorCondition = condition; // Wake up the thread that is waiting in the #authenticate method notify(); }