SMACK-282: Support SASL-related error conditions

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11616 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Günther Niess 2010-02-09 12:40:11 +00:00 committed by niess
parent e3efee2e8f
commit 539f652443
2 changed files with 40 additions and 6 deletions

View File

@ -286,7 +286,7 @@ class PacketReader {
// depending on the number of retries // depending on the number of retries
final Failure failure = PacketParserUtils.parseSASLFailure(parser); final Failure failure = PacketParserUtils.parseSASLFailure(parser);
processPacket(failure); processPacket(failure);
connection.getSASLAuthentication().authenticationFailed(); connection.getSASLAuthentication().authenticationFailed(failure.getCondition());
} }
} }
else if (parser.getName().equals("challenge")) { else if (parser.getName().equals("challenge")) {

View File

@ -80,6 +80,10 @@ public class SASLAuthentication implements UserAuthentication {
private boolean saslFailed; private boolean saslFailed;
private boolean resourceBinded; private boolean resourceBinded;
private boolean sessionSupported; private boolean sessionSupported;
/**
* The SASL related error condition if there was one provided by the server.
*/
private String errorCondition;
static { static {
@ -247,8 +251,14 @@ public class SASLAuthentication implements UserAuthentication {
if (saslFailed) { if (saslFailed) {
// SASL authentication failed and the server may have closed the connection // SASL authentication failed and the server may have closed the connection
// so throw an exception // so throw an exception
throw new XMPPException("SASL authentication failed using mechanism " + if (errorCondition != null) {
selectedMechanism); throw new XMPPException("SASL authentication " +
selectedMechanism + " failed: " + errorCondition);
}
else {
throw new XMPPException("SASL authentication failed using mechanism " +
selectedMechanism);
}
} }
if (saslNegotiated) { if (saslNegotiated) {
@ -323,8 +333,14 @@ public class SASLAuthentication implements UserAuthentication {
if (saslFailed) { if (saslFailed) {
// SASL authentication failed and the server may have closed the connection // SASL authentication failed and the server may have closed the connection
// so throw an exception // so throw an exception
throw new XMPPException("SASL authentication failed using mechanism " + if (errorCondition != null) {
selectedMechanism); throw new XMPPException("SASL authentication " +
selectedMechanism + " failed: " + errorCondition);
}
else {
throw new XMPPException("SASL authentication failed using mechanism " +
selectedMechanism);
}
} }
if (saslNegotiated) { if (saslNegotiated) {
@ -384,7 +400,12 @@ public class SASLAuthentication implements UserAuthentication {
if (saslFailed) { if (saslFailed) {
// SASL authentication failed and the server may have closed the connection // SASL authentication failed and the server may have closed the connection
// so throw an exception // 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) { if (saslNegotiated) {
@ -508,10 +529,23 @@ public class SASLAuthentication implements UserAuthentication {
/** /**
* Notification message saying that SASL authentication has failed. The server may have * Notification message saying that SASL authentication has failed. The server may have
* closed the connection depending on the number of possible retries. * closed the connection depending on the number of possible retries.
*
* @deprecated replaced by {@see #authenticationFailed(String)}.
*/ */
void authenticationFailed() { 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) { synchronized (this) {
saslFailed = true; saslFailed = true;
errorCondition = condition;
// Wake up the thread that is waiting in the #authenticate method // Wake up the thread that is waiting in the #authenticate method
notify(); notify();
} }