1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 04:57:58 +01:00

Switch 'username' paramater to CharSequence

instead of String. So that jxmpp-jids Localpart class can also be used
as argument.
Note that the username is not always the localpart!
This commit is contained in:
Florian Schmaus 2015-01-18 20:54:41 +01:00
parent 31d573753b
commit cb67f1d5c3
2 changed files with 11 additions and 18 deletions

View file

@ -400,7 +400,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} else {
// The previously used username, password and resource take over precedence over the
// ones from the connection configuration
String username = usedUsername != null ? usedUsername : config.getUsername();
CharSequence username = usedUsername != null ? usedUsername : config.getUsername();
String password = usedPassword != null ? usedPassword : config.getPassword();
String resource = usedResource != null ? usedResource : config.getResource();
login(username, password, resource);
@ -408,7 +408,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
/**
* Same as {@link #login(String, String, String)}, but takes the resource from the connection
* Same as {@link #login(CharSequence, String, String)}, but takes the resource from the connection
* configuration.
*
* @param username
@ -418,7 +418,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @throws IOException
* @see #login
*/
public synchronized void login(String username, String password) throws XMPPException, SmackException,
public synchronized void login(CharSequence username, String password) throws XMPPException, SmackException,
IOException {
login(username, password, config.getResource());
}
@ -435,17 +435,17 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @throws IOException
* @see #login
*/
public synchronized void login(String username, String password, String resource) throws XMPPException,
public synchronized void login(CharSequence username, String password, String resource) throws XMPPException,
SmackException, IOException {
if (!config.allowNullOrEmptyUsername && StringUtils.isNullOrEmpty(username)) {
throw new IllegalArgumentException("Username must not be null or empty");
}
throwNotConnectedExceptionIfAppropriate();
throwAlreadyLoggedInExceptionIfAppropriate();
usedUsername = username;
usedUsername = username != null ? username.toString() : null;
usedPassword = password;
usedResource = resource;
loginNonAnonymously(username, password, resource);
loginNonAnonymously(usedUsername, usedPassword, usedResource);
}
protected abstract void loginNonAnonymously(String username, String password, String resource)

View file

@ -17,8 +17,6 @@
package org.jivesoftware.smack;
import java.util.Locale;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.proxy.ProxyInfo;
import org.jivesoftware.smack.rosterstore.RosterStore;
@ -65,7 +63,7 @@ public abstract class ConnectionConfiguration {
// Holds the socket factory that is used to generate the socket in the connection
private final SocketFactory socketFactory;
private final String username;
private final CharSequence username;
private final String password;
private final String resource;
private final boolean sendPresence;
@ -96,12 +94,7 @@ public abstract class ConnectionConfiguration {
protected final boolean allowNullOrEmptyUsername;
protected ConnectionConfiguration(Builder<?,?> builder) {
if (builder.username != null) {
// Do partial version of nameprep on the username.
username = builder.username.toLowerCase(Locale.US).trim();
} else {
username = null;
}
username = builder.username;
password = builder.password;
callbackHandler = builder.callbackHandler;
@ -329,7 +322,7 @@ public abstract class ConnectionConfiguration {
*
* @return the username to use when trying to reconnect to the server.
*/
public String getUsername() {
public CharSequence getUsername() {
return this.username;
}
@ -397,7 +390,7 @@ public abstract class ConnectionConfiguration {
private String[] enabledSSLProtocols;
private String[] enabledSSLCiphers;
private HostnameVerifier hostnameVerifier;
private String username;
private CharSequence username;
private String password;
private String resource = "Smack";
private boolean sendPresence = true;
@ -427,7 +420,7 @@ public abstract class ConnectionConfiguration {
* @param password the password or token used to authenticate
* @return a reference to this builder.
*/
public B setUsernameAndPassword(String username, String password) {
public B setUsernameAndPassword(CharSequence username, String password) {
this.username = username;
this.password = password;
return getThis();