1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-11 01:59:38 +02: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:
Gaston Dombiak 2005-09-05 21:57:33 +00:00 committed by gato
parent 5b1eea6833
commit 6d6fdcf9b6
2 changed files with 48 additions and 0 deletions

View file

@ -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();
}
}
}