diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
index 6bc5d012e..448ae49d1 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
@@ -73,6 +73,7 @@ import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
+import org.jivesoftware.smack.sasl.core.SASLAnonymous;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.PacketParserUtils;
@@ -551,8 +552,19 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
public final boolean isAnonymous() {
- return config.getUsername() == null && usedUsername == null
- && !config.allowNullOrEmptyUsername;
+ return isAuthenticated() && SASLAnonymous.NAME.equals(getUsedSaslMechansism());
+ }
+
+ /**
+ * Get the name of the SASL mechanism that was used to authenticate this connection. This returns the name of
+ * mechanism which was used the last time this conneciton was authenticated, and will return null
if
+ * this connection was not authenticated before.
+ *
+ * @return the name of the used SASL mechanism.
+ * @since 4.2
+ */
+ public final String getUsedSaslMechansism() {
+ return saslAuthentication.getNameOfLastUsedSaslMechansism();
}
private DomainBareJid xmppServiceDomain;
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 be98d93e6..b15ce272b 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
@@ -56,7 +56,7 @@ import java.util.logging.Logger;
* @author Gaston Dombiak
* @author Jay Kline
*/
-public class SASLAuthentication {
+public final class SASLAuthentication {
private static final Logger LOGGER = Logger.getLogger(SASLAuthentication.class.getName());
@@ -294,11 +294,19 @@ public class SASLAuthentication {
* is used by the connection at the first login and then reused after the connection
* is disconnected and then reconnected.
*/
- protected void init() {
+ void init() {
authenticationSuccessful = false;
saslException = null;
}
+ String getNameOfLastUsedSaslMechansism() {
+ SASLMechanism lastUsedMech = currentMechanism;
+ if (lastUsedMech == null) {
+ return null;
+ }
+ return lastUsedMech.getName();
+ }
+
private SASLMechanism selectMechanism() throws SmackException {
Iterator it = REGISTERED_MECHANISMS.iterator();
final List serverMechanisms = getServerMechanisms();