public 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 resource,
CallbackHandler cbh)
Performs SASL authentication of the specified user.
|
void |
authenticate(String username,
String password,
String resource)
Performs SASL authentication of the specified user.
|
void |
authenticateAnonymously()
Performs ANONYMOUS SASL authentication.
|
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 mechansim) |
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.
|
boolean |
hasAnonymousAuthentication()
Returns true if the server offered ANONYMOUS SASL as a way to authenticate users.
|
boolean |
hasNonAnonymousAuthentication()
Returns true if the server offered SASL authentication besides ANONYMOUS SASL.
|
protected void |
init()
Initializes the internal state in order to be able to be reused.
|
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 unregisterSASLMechanism(String clazz)
clazz
- the SASLMechanism class's namepublic static boolean blacklistSASLMechanism(String mechansim)
public static boolean unBlacklistSASLMechanism(String mechanism)
public static Set<String> getBlacklistedSASLMechanisms()
public boolean hasAnonymousAuthentication()
public boolean hasNonAnonymousAuthentication()
public void authenticate(String resource, CallbackHandler cbh) throws IOException, XMPPException.XMPPErrorException, SASLErrorException, SmackException
The server may assign a full JID with a username or resource different than the requested by this method.
resource
- the desired resource.cbh
- the CallbackHandler used to get information from the userIOException
XMPPException.XMPPErrorException
SASLErrorException
SmackException
public void authenticate(String username, String password, String resource) throws XMPPException.XMPPErrorException, SASLErrorException, IOException, SmackException
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.resource
- the desired resource.XMPPException.XMPPErrorException
SASLErrorException
IOException
SmackException
public void authenticateAnonymously() throws SASLErrorException, SmackException, XMPPException.XMPPErrorException
The server will assign a full JID with a randomly generated resource and possibly with no username.
SASLErrorException
XMPPException.XMPPErrorException
- if an error occures while authenticating.SmackException
- if there was no response from the server.public void challengeReceived(String challenge) throws SmackException
challenge
- a base64 encoded string representing the challenge.SmackException
public void challengeReceived(String challenge, boolean finalChallenge) throws SmackException
challenge
- a base64 encoded string representing the challenge.finalChallenge
- true if this is the last challenge send by the server within the success stanzaSmackException
public void authenticated(SaslStreamElements.Success success) throws SmackException
SmackException
public void authenticationFailed(SaslStreamElements.SASLFailure saslFailure)
saslFailure
- the SASL failure as reported by the serverpublic void authenticationFailed(Exception exception)
public boolean authenticationSuccessful()
protected void init()