mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 08:12:05 +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:
parent
31d573753b
commit
cb67f1d5c3
2 changed files with 11 additions and 18 deletions
|
@ -400,7 +400,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
} else {
|
} else {
|
||||||
// The previously used username, password and resource take over precedence over the
|
// The previously used username, password and resource take over precedence over the
|
||||||
// ones from the connection configuration
|
// 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 password = usedPassword != null ? usedPassword : config.getPassword();
|
||||||
String resource = usedResource != null ? usedResource : config.getResource();
|
String resource = usedResource != null ? usedResource : config.getResource();
|
||||||
login(username, password, resource);
|
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.
|
* configuration.
|
||||||
*
|
*
|
||||||
* @param username
|
* @param username
|
||||||
|
@ -418,7 +418,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @see #login
|
* @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 {
|
IOException {
|
||||||
login(username, password, config.getResource());
|
login(username, password, config.getResource());
|
||||||
}
|
}
|
||||||
|
@ -435,17 +435,17 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @see #login
|
* @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 {
|
SmackException, IOException {
|
||||||
if (!config.allowNullOrEmptyUsername && StringUtils.isNullOrEmpty(username)) {
|
if (!config.allowNullOrEmptyUsername && StringUtils.isNullOrEmpty(username)) {
|
||||||
throw new IllegalArgumentException("Username must not be null or empty");
|
throw new IllegalArgumentException("Username must not be null or empty");
|
||||||
}
|
}
|
||||||
throwNotConnectedExceptionIfAppropriate();
|
throwNotConnectedExceptionIfAppropriate();
|
||||||
throwAlreadyLoggedInExceptionIfAppropriate();
|
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||||
usedUsername = username;
|
usedUsername = username != null ? username.toString() : null;
|
||||||
usedPassword = password;
|
usedPassword = password;
|
||||||
usedResource = resource;
|
usedResource = resource;
|
||||||
loginNonAnonymously(username, password, resource);
|
loginNonAnonymously(usedUsername, usedPassword, usedResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void loginNonAnonymously(String username, String password, String resource)
|
protected abstract void loginNonAnonymously(String username, String password, String resource)
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.Session;
|
import org.jivesoftware.smack.packet.Session;
|
||||||
import org.jivesoftware.smack.proxy.ProxyInfo;
|
import org.jivesoftware.smack.proxy.ProxyInfo;
|
||||||
import org.jivesoftware.smack.rosterstore.RosterStore;
|
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
|
// Holds the socket factory that is used to generate the socket in the connection
|
||||||
private final SocketFactory socketFactory;
|
private final SocketFactory socketFactory;
|
||||||
|
|
||||||
private final String username;
|
private final CharSequence username;
|
||||||
private final String password;
|
private final String password;
|
||||||
private final String resource;
|
private final String resource;
|
||||||
private final boolean sendPresence;
|
private final boolean sendPresence;
|
||||||
|
@ -96,12 +94,7 @@ public abstract class ConnectionConfiguration {
|
||||||
protected final boolean allowNullOrEmptyUsername;
|
protected final boolean allowNullOrEmptyUsername;
|
||||||
|
|
||||||
protected ConnectionConfiguration(Builder<?,?> builder) {
|
protected ConnectionConfiguration(Builder<?,?> builder) {
|
||||||
if (builder.username != null) {
|
username = builder.username;
|
||||||
// Do partial version of nameprep on the username.
|
|
||||||
username = builder.username.toLowerCase(Locale.US).trim();
|
|
||||||
} else {
|
|
||||||
username = null;
|
|
||||||
}
|
|
||||||
password = builder.password;
|
password = builder.password;
|
||||||
callbackHandler = builder.callbackHandler;
|
callbackHandler = builder.callbackHandler;
|
||||||
|
|
||||||
|
@ -329,7 +322,7 @@ public abstract class ConnectionConfiguration {
|
||||||
*
|
*
|
||||||
* @return the username to use when trying to reconnect to the server.
|
* @return the username to use when trying to reconnect to the server.
|
||||||
*/
|
*/
|
||||||
public String getUsername() {
|
public CharSequence getUsername() {
|
||||||
return this.username;
|
return this.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +390,7 @@ public abstract class ConnectionConfiguration {
|
||||||
private String[] enabledSSLProtocols;
|
private String[] enabledSSLProtocols;
|
||||||
private String[] enabledSSLCiphers;
|
private String[] enabledSSLCiphers;
|
||||||
private HostnameVerifier hostnameVerifier;
|
private HostnameVerifier hostnameVerifier;
|
||||||
private String username;
|
private CharSequence username;
|
||||||
private String password;
|
private String password;
|
||||||
private String resource = "Smack";
|
private String resource = "Smack";
|
||||||
private boolean sendPresence = true;
|
private boolean sendPresence = true;
|
||||||
|
@ -427,7 +420,7 @@ public abstract class ConnectionConfiguration {
|
||||||
* @param password the password or token used to authenticate
|
* @param password the password or token used to authenticate
|
||||||
* @return a reference to this builder.
|
* @return a reference to this builder.
|
||||||
*/
|
*/
|
||||||
public B setUsernameAndPassword(String username, String password) {
|
public B setUsernameAndPassword(CharSequence username, String password) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
return getThis();
|
return getThis();
|
||||||
|
|
Loading…
Reference in a new issue