From 5b1d2664af583e7c88101a1040e6c8ea3640ed78 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 23 Sep 2019 19:47:37 +0200 Subject: [PATCH] Clear saslException class field before throwing Thanks to PolFW, who writes: A SASLErrorException is thrown before we have received the "". This is because SASLAuthentication is keeping a reference to a "saslException" so to clear that after a authentication failure we have to invoke again connect on the xmpptcpconnection to initialize again the saslAuthentication. But it doesn't solve the issue because an AlreadyConnectedException is thrown before the initialisation of the "this.saslAuthentication.init();" Note that the user uses one time tokens for authentication. --- .../java/org/jivesoftware/smack/SASLAuthentication.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java index 15175d2b0..2fe581b17 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java @@ -216,6 +216,11 @@ public final class SASLAuthentication { } if (saslException != null) { + Exception saslException = this.saslException; + // Clear the saslException class field, so that this exception is not thrown after a new authenticate() + // invocation (with different credentials). + this.saslException = null; + if (saslException instanceof SmackSaslException) { throw (SmackSaslException) saslException; } else if (saslException instanceof SASLErrorException) { @@ -321,7 +326,6 @@ public final class SASLAuthentication { */ void init() { authenticationSuccessful = false; - saslException = null; } String getNameOfLastUsedSaslMechansism() {