1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 23:42:06 +01:00

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
final Failure failure = PacketParserUtils.parseSASLFailure(parser);
processPacket(failure);
connection.getSASLAuthentication().authenticationFailed();
connection.getSASLAuthentication().authenticationFailed(failure.getCondition());
}
}
else if (parser.getName().equals("challenge")) {

View file

@ -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();
}