public final class SASLAuthentication extends Object
This class is responsible authenticating the user using SASL, binding the resource to the connection and establishing a session with the server.
Once TLS has been negotiated (i.e. the connection has been secured) it is possible to register with the server or authenticate using SASL. If the server supports SASL then Smack will try to authenticate using SASL..
The server may support many SASL mechanisms to use for authenticating. Out of the box
Smack provides several SASL mechanisms, but it is possible to register new SASL Mechanisms. Use
registerSASLMechanism(SASLMechanism)
to register a new mechanisms.
SASLMechanism
Modifier and Type | Method and Description |
---|---|
void |
authenticate(String username,
String password,
EntityBareJid authzid,
SSLSession sslSession)
Performs SASL authentication of the specified user.
|
void |
authenticated(SaslStreamElements.Success success)
Notification message saying that SASL authentication was successful.
|
void |
authenticationFailed(Exception exception) |
void |
authenticationFailed(SaslStreamElements.SASLFailure saslFailure)
Notification message saying that SASL authentication has failed.
|
boolean |
authenticationSuccessful() |
static boolean |
blacklistSASLMechanism(String mechanism) |
void |
challengeReceived(String challenge)
|
void |
challengeReceived(String challenge,
boolean finalChallenge)
The server is challenging the SASL authentication we just sent.
|
static Set<String> |
getBlacklistedSASLMechanisms() |
static Map<String,String> |
getRegisterdSASLMechanisms()
Returns the registered SASLMechanism sorted by the level of preference.
|
static boolean |
isSaslMechanismRegistered(String saslMechanism) |
static void |
registerSASLMechanism(SASLMechanism mechanism)
Registers a new SASL mechanism.
|
static boolean |
unBlacklistSASLMechanism(String mechanism) |
static boolean |
unregisterSASLMechanism(String clazz)
Unregister a SASLMechanism by it's full class name.
|
public static void registerSASLMechanism(SASLMechanism mechanism)
mechanism
- a SASLMechanism subclass.public static Map<String,String> getRegisterdSASLMechanisms()
public static boolean isSaslMechanismRegistered(String saslMechanism)
public static boolean unregisterSASLMechanism(String clazz)
clazz
- the SASLMechanism class's namepublic static boolean blacklistSASLMechanism(String mechanism)
public static boolean unBlacklistSASLMechanism(String mechanism)
public static Set<String> getBlacklistedSASLMechanisms()
public void authenticate(String username, String password, EntityBareJid authzid, SSLSession sslSession) throws XMPPException.XMPPErrorException, SASLErrorException, IOException, SmackException, InterruptedException
The server may assign a full JID with a username or resource different than the requested by this method.
username
- the username that is authenticating with the server.password
- the password to send to the server.authzid
- the authorization identifier (typically null).sslSession
- the optional SSL/TLS session (if one was established)XMPPException.XMPPErrorException
SASLErrorException
IOException
SmackException
InterruptedException
public void challengeReceived(String challenge) throws SmackException, InterruptedException
challenge
- a base64 encoded string representing the challenge.SmackException
InterruptedException
public void challengeReceived(String challenge, boolean finalChallenge) throws SmackException, InterruptedException
challenge
- a base64 encoded string representing the challenge.finalChallenge
- true if this is the last challenge send by the server within the success stanzaSmackException
InterruptedException
public void authenticated(SaslStreamElements.Success success) throws SmackException, InterruptedException
success
- result of the authentication.SmackException
InterruptedException
public void authenticationFailed(SaslStreamElements.SASLFailure saslFailure)
saslFailure
- the SASL failure as reported by the serverpublic void authenticationFailed(Exception exception)
public boolean authenticationSuccessful()