|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jivesoftware.smack.SASLAuthentication
public class SASLAuthentication
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, authenticate using Non-SASL or authenticate using SASL. If the server supports SASL then Smack will first try to authenticate using SASL. But if that fails then Non-SASL will be tried.
The server may support many SASL mechanisms to use for authenticating. Out of the box
Smack provides SASL PLAIN but it is possible to register new SASL Mechanisms. Use
registerSASLMechanism(int, String, Class)
to add new mechanisms. See
SASLMechanism
.
Once the user has been authenticated with SASL, it is necessary to bind a resource for
the connection. If no resource is passed in authenticate(String, String, String)
then the server will assign a resource for the connection. In case a resource is passed
then the server will receive the desired resource but may assign a modified resource for
the connection.
Once a resource has been binded and if the server supports sessions then Smack will establish a session so that instant messaging and presence functionalities may be used.
Method Summary | |
---|---|
String |
authenticate(String username,
String password,
String resource)
Performs SASL authentication of the specified user. |
String |
authenticateAnonymously()
Performs ANONYMOUS SASL authentication. |
static List<Class> |
getRegisterSASLMechanisms()
Returns the registerd SASLMechanism classes 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. |
boolean |
isAuthenticated()
Returns true if the user was able to authenticate with the server usins SASL. |
static void |
registerSASLMechanism(int index,
String name,
Class mClass)
Registers a new SASL mechanism in the specified preference position. |
void |
send(String stanza)
|
static void |
unregisterSASLMechanism(String name)
Unregisters an existing SASL mechanism. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void registerSASLMechanism(int index, String name, Class mClass)
index
- preference position amongst all the implemented SASL mechanism. Starts with 0.name
- common name of the SASL mechanism. E.g.: PLAIN, DIGEST-MD5 or KERBEROS_V4.mClass
- a SASLMechanism subclass.public static void unregisterSASLMechanism(String name)
name
- common name of the SASL mechanism. E.g.: PLAIN, DIGEST-MD5 or KERBEROS_V4.public static List<Class> getRegisterSASLMechanisms()
public boolean hasAnonymousAuthentication()
public boolean hasNonAnonymousAuthentication()
public String authenticate(String username, String password, String resource) throws XMPPException
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
- if an error occures while authenticating.public String authenticateAnonymously() throws XMPPException
The server will assign a full JID with a randomly generated resource and possibly with no username.
XMPPException
- if an error occures while authenticating.public boolean isAuthenticated()
public void send(String stanza) throws IOException
IOException
protected void init()
|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |