mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02: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:
parent
e3efee2e8f
commit
539f652443
2 changed files with 40 additions and 6 deletions
|
@ -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")) {
|
||||||
|
|
|
@ -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,9 +251,15 @@ 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
|
||||||
|
if (errorCondition != null) {
|
||||||
|
throw new XMPPException("SASL authentication " +
|
||||||
|
selectedMechanism + " failed: " + errorCondition);
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new XMPPException("SASL authentication failed using mechanism " +
|
throw new XMPPException("SASL authentication failed using mechanism " +
|
||||||
selectedMechanism);
|
selectedMechanism);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (saslNegotiated) {
|
if (saslNegotiated) {
|
||||||
// Bind a resource for this connection and
|
// Bind a resource for this connection and
|
||||||
|
@ -323,9 +333,15 @@ 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
|
||||||
|
if (errorCondition != null) {
|
||||||
|
throw new XMPPException("SASL authentication " +
|
||||||
|
selectedMechanism + " failed: " + errorCondition);
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new XMPPException("SASL authentication failed using mechanism " +
|
throw new XMPPException("SASL authentication failed using mechanism " +
|
||||||
selectedMechanism);
|
selectedMechanism);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (saslNegotiated) {
|
if (saslNegotiated) {
|
||||||
// Bind a resource for this connection and
|
// Bind a resource for this connection and
|
||||||
|
@ -384,8 +400,13 @@ 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
|
||||||
|
if (errorCondition != null) {
|
||||||
|
throw new XMPPException("SASL authentication failed: " + errorCondition);
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new XMPPException("SASL authentication failed");
|
throw new XMPPException("SASL authentication failed");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (saslNegotiated) {
|
if (saslNegotiated) {
|
||||||
// Bind a resource for this connection and
|
// 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
|
* 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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue