mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Remove resource binding out of sasl auth
Follow XEP-170 recommendations: Resource binding *after* compression. Fixes also a bunch of race conditions related to the wait()/notify() pattern used in the early stages of a Connection where createPacketCollectorAndSend(Packet).nextResultOrThrow() can not be used. Those wait()/notify() patterns are currently - SASL authentication - compression - resource binding Fixes SMACK-454
This commit is contained in:
parent
d17f64ed9a
commit
874a22489e
7 changed files with 188 additions and 165 deletions
|
@ -148,10 +148,10 @@ public class BOSHPacketReader implements BOSHClientResponseListener {
|
|||
} else if (parser.getName().equals("bind")) {
|
||||
// The server requires the client to bind a resource to the
|
||||
// stream
|
||||
connection.getSASLAuthentication().bindingRequired();
|
||||
connection.serverRequiresBinding();
|
||||
} else if (parser.getName().equals("session")) {
|
||||
// The server supports sessions
|
||||
connection.getSASLAuthentication().sessionsSupported();
|
||||
connection.serverSupportsSession();
|
||||
} else if (parser.getName().equals("register")) {
|
||||
AccountManager.getInstance(connection).setSupportsAccountCreation(true);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,8 @@ public class XMPPBOSHConnection extends XMPPConnection {
|
|||
this.config = config;
|
||||
}
|
||||
|
||||
public void connect() throws SmackException {
|
||||
@Override
|
||||
void connectInternal() throws SmackException {
|
||||
if (connected) {
|
||||
throw new IllegalStateException("Already connected to a server.");
|
||||
}
|
||||
|
@ -146,7 +147,6 @@ public class XMPPBOSHConnection extends XMPPConnection {
|
|||
client.close();
|
||||
client = null;
|
||||
}
|
||||
saslAuthentication.init();
|
||||
sessionID = null;
|
||||
authID = null;
|
||||
|
||||
|
@ -250,18 +250,18 @@ public class XMPPBOSHConnection extends XMPPConnection {
|
|||
// Do partial version of nameprep on the username.
|
||||
username = username.toLowerCase(Locale.US).trim();
|
||||
|
||||
String response;
|
||||
if (saslAuthentication.hasNonAnonymousAuthentication()) {
|
||||
// Authenticate using SASL
|
||||
if (password != null) {
|
||||
response = saslAuthentication.authenticate(username, password, resource);
|
||||
saslAuthentication.authenticate(username, password, resource);
|
||||
} else {
|
||||
response = saslAuthentication.authenticate(resource, config.getCallbackHandler());
|
||||
saslAuthentication.authenticate(resource, config.getCallbackHandler());
|
||||
}
|
||||
} else {
|
||||
throw new SaslException("No non-anonymous SASL authentication mechanism available");
|
||||
}
|
||||
|
||||
String response = bindResourceAndEstablishSession(resource);
|
||||
// Set the user.
|
||||
if (response != null) {
|
||||
this.user = response;
|
||||
|
@ -303,15 +303,15 @@ public class XMPPBOSHConnection extends XMPPConnection {
|
|||
throw new AlreadyLoggedInException();
|
||||
}
|
||||
|
||||
String response;
|
||||
if (saslAuthentication.hasAnonymousAuthentication()) {
|
||||
response = saslAuthentication.authenticateAnonymously();
|
||||
saslAuthentication.authenticateAnonymously();
|
||||
}
|
||||
else {
|
||||
// Authenticate using Non-SASL
|
||||
throw new SaslException("No anonymous SASL authentication mechanism available");
|
||||
}
|
||||
|
||||
String response = bindResourceAndEstablishSession(null);
|
||||
// Set the user value.
|
||||
this.user = response;
|
||||
// Update the serviceName with the one returned by the server
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue