mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-23 04:57:58 +01:00
Add AbstractXMPPConnection.getUsedSaslMechanism()
and improve isAnonymous(). Also some minor changes to SASLAuthentication.
This commit is contained in:
parent
f369a009ac
commit
3c2ba0ec43
2 changed files with 24 additions and 4 deletions
|
@ -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 <code>null</code> 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;
|
||||
|
|
|
@ -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<SASLMechanism> it = REGISTERED_MECHANISMS.iterator();
|
||||
final List<String> serverMechanisms = getServerMechanisms();
|
||||
|
|
Loading…
Reference in a new issue