1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22: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,9 +251,15 @@ public class SASLAuthentication implements UserAuthentication {
if (saslFailed) {
// SASL authentication failed and the server may have closed the connection
// so throw an exception
if (errorCondition != null) {
throw new XMPPException("SASL authentication " +
selectedMechanism + " failed: " + errorCondition);
}
else {
throw new XMPPException("SASL authentication failed using mechanism " +
selectedMechanism);
}
}
if (saslNegotiated) {
// Bind a resource for this connection and
@ -323,9 +333,15 @@ public class SASLAuthentication implements UserAuthentication {
if (saslFailed) {
// SASL authentication failed and the server may have closed the connection
// so throw an exception
if (errorCondition != null) {
throw new XMPPException("SASL authentication " +
selectedMechanism + " failed: " + errorCondition);
}
else {
throw new XMPPException("SASL authentication failed using mechanism " +
selectedMechanism);
}
}
if (saslNegotiated) {
// Bind a resource for this connection and
@ -384,8 +400,13 @@ public class SASLAuthentication implements UserAuthentication {
if (saslFailed) {
// SASL authentication failed and the server may have closed the connection
// so throw an exception
if (errorCondition != null) {
throw new XMPPException("SASL authentication failed: " + errorCondition);
}
else {
throw new XMPPException("SASL authentication failed");
}
}
if (saslNegotiated) {
// Bind a resource for this connection and
@ -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();
}