mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-27 00:32:07 +01:00
Added anonymous authentication. SMACK-84
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2782 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
5b1eea6833
commit
6d6fdcf9b6
2 changed files with 48 additions and 0 deletions
|
@ -98,4 +98,31 @@ class NonSASLAuthentication implements UserAuthentication {
|
|||
|
||||
return response.getTo();
|
||||
}
|
||||
|
||||
public String authenticateAnonymously() throws XMPPException {
|
||||
// Create the authentication packet we'll send to the server.
|
||||
Authentication auth = new Authentication();
|
||||
|
||||
PacketCollector collector =
|
||||
connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
|
||||
// Send the packet.
|
||||
connection.sendPacket(auth);
|
||||
// Wait up to a certain number of seconds for a response from the server.
|
||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||
if (response == null) {
|
||||
throw new XMPPException("Anonymous login failed.");
|
||||
}
|
||||
else if (response.getType() == IQ.Type.ERROR) {
|
||||
throw new XMPPException(response.getError());
|
||||
}
|
||||
// We're done with the collector, so explicitly cancel it.
|
||||
collector.cancel();
|
||||
|
||||
if (response.getTo() != null) {
|
||||
return response.getTo();
|
||||
}
|
||||
else {
|
||||
return connection.serviceName + "/" + ((Authentication) response).getResource();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,27 @@ package org.jivesoftware.smack;
|
|||
*/
|
||||
interface UserAuthentication {
|
||||
|
||||
/**
|
||||
* Authenticates the user with the server. This method will return the full JID provided by
|
||||
* the server. The server may assign a full JID with a username and resource different than
|
||||
* the requested by this method.
|
||||
*
|
||||
* @param username the username that is authenticating with the server.
|
||||
* @param password the password to send to the server.
|
||||
* @param resource the desired resource.
|
||||
* @return the full JID provided by the server while binding a resource for the connection.
|
||||
* @throws XMPPException if an error occures while authenticating.
|
||||
*/
|
||||
String authenticate(String username, String password, String resource) throws
|
||||
XMPPException;
|
||||
|
||||
/**
|
||||
* Performs an anonymous authentication with the server. The server will created a new full JID
|
||||
* for this connection. An exception will be thrown if the server does not support anonymous
|
||||
* authentication.
|
||||
*
|
||||
* @return the full JID provided by the server while binding a resource for the connection.
|
||||
* @throws XMPPException if an error occures while authenticating.
|
||||
*/
|
||||
String authenticateAnonymously() throws XMPPException;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue