2006-01-17 21:02:11 +01:00
|
|
|
/**
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2006-01-17 21:02:11 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2006-01-17 21:02:11 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smack;
|
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2014-03-15 14:47:55 +01:00
|
|
|
import org.jivesoftware.smack.packet.Session;
|
2008-07-15 04:59:21 +02:00
|
|
|
import org.jivesoftware.smack.proxy.ProxyInfo;
|
2014-08-16 14:26:45 +02:00
|
|
|
import org.jivesoftware.smack.rosterstore.RosterStore;
|
2006-10-16 22:45:43 +02:00
|
|
|
|
2006-09-14 21:16:40 +02:00
|
|
|
import javax.net.SocketFactory;
|
2014-07-21 18:42:44 +02:00
|
|
|
import javax.net.ssl.HostnameVerifier;
|
2013-02-26 09:44:17 +01:00
|
|
|
import javax.net.ssl.SSLContext;
|
2008-10-24 07:17:50 +02:00
|
|
|
import javax.security.auth.callback.CallbackHandler;
|
2013-11-10 15:02:57 +01:00
|
|
|
|
2006-01-17 21:02:11 +01:00
|
|
|
/**
|
2014-11-09 18:30:16 +01:00
|
|
|
* Configuration to use while establishing the connection to the server.
|
2006-01-17 21:02:11 +01:00
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2014-11-09 18:30:16 +01:00
|
|
|
public abstract class ConnectionConfiguration {
|
2006-01-17 21:02:11 +01:00
|
|
|
|
2014-10-19 21:48:17 +02:00
|
|
|
static {
|
|
|
|
// Ensure that Smack is initialized when ConnectionConfiguration is used, or otherwise e.g.
|
|
|
|
// SmackConfiguration.DEBUG_ENABLED may not be initialized yet.
|
|
|
|
SmackConfiguration.getVersion();
|
|
|
|
}
|
|
|
|
|
2010-02-09 12:55:56 +01:00
|
|
|
/**
|
|
|
|
* Hostname of the XMPP server. Usually servers use the same service name as the name
|
|
|
|
* of the server. However, there are some servers like google where host would be
|
|
|
|
* talk.google.com and the serviceName would be gmail.com.
|
|
|
|
*/
|
2014-11-09 18:30:16 +01:00
|
|
|
protected final String serviceName;
|
|
|
|
protected final String host;
|
|
|
|
protected final int port;
|
2006-01-17 21:02:11 +01:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
private final String keystorePath;
|
|
|
|
private final String keystoreType;
|
|
|
|
private final String pkcs11Library;
|
|
|
|
private final SSLContext customSSLContext;
|
2006-01-17 21:02:11 +01:00
|
|
|
|
2008-10-24 07:17:50 +02:00
|
|
|
/**
|
|
|
|
* Used to get information from the user
|
|
|
|
*/
|
2014-11-09 18:30:16 +01:00
|
|
|
private final CallbackHandler callbackHandler;
|
2006-01-17 21:02:11 +01:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
private final boolean debuggerEnabled;
|
2006-01-17 21:02:11 +01:00
|
|
|
|
2006-09-14 21:16:40 +02:00
|
|
|
// Holds the socket factory that is used to generate the socket in the connection
|
2014-11-09 18:30:16 +01:00
|
|
|
private final SocketFactory socketFactory;
|
|
|
|
|
|
|
|
private final String username;
|
|
|
|
private final String password;
|
|
|
|
private final String resource;
|
|
|
|
private final boolean sendPresence;
|
|
|
|
private final boolean rosterLoadedAtLogin;
|
|
|
|
private final boolean legacySessionDisabled;
|
|
|
|
private final SecurityMode securityMode;
|
2013-11-10 15:02:57 +01:00
|
|
|
|
2014-05-29 09:21:04 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-11-09 18:30:16 +01:00
|
|
|
private final String[] enabledSSLProtocols;
|
2014-05-29 09:21:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-11-09 18:30:16 +01:00
|
|
|
private final String[] enabledSSLCiphers;
|
2014-05-29 09:21:04 +02:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
private final HostnameVerifier hostnameVerifier;
|
2014-07-21 18:42:44 +02:00
|
|
|
|
2013-11-10 15:02:57 +01:00
|
|
|
/**
|
|
|
|
* Permanent store for the Roster, needed for roster versioning
|
|
|
|
*/
|
2014-11-09 18:30:16 +01:00
|
|
|
private final RosterStore rosterStore;
|
2013-11-10 15:02:57 +01:00
|
|
|
|
|
|
|
// Holds the proxy information (such as proxyhost, proxyport, username, password etc)
|
2014-11-09 18:30:16 +01:00
|
|
|
protected final ProxyInfo proxy;
|
|
|
|
|
2015-01-10 11:18:07 +01:00
|
|
|
protected final boolean allowNullOrEmptyUsername;
|
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
protected ConnectionConfiguration(Builder<?,?> builder) {
|
2014-11-09 18:30:16 +01:00
|
|
|
if (builder.username != null) {
|
|
|
|
// Do partial version of nameprep on the username.
|
|
|
|
username = builder.username.toLowerCase(Locale.US).trim();
|
|
|
|
} else {
|
|
|
|
username = null;
|
|
|
|
}
|
|
|
|
password = builder.password;
|
|
|
|
callbackHandler = builder.callbackHandler;
|
2006-10-16 22:45:43 +02:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
// Resource can be null, this means that the server must provide one
|
|
|
|
resource = builder.resource;
|
2006-10-16 22:45:43 +02:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
serviceName = builder.serviceName;
|
|
|
|
if (serviceName == null) {
|
|
|
|
throw new IllegalArgumentException("Must provide XMPP service name");
|
2014-08-01 23:20:35 +02:00
|
|
|
}
|
2014-11-09 18:30:16 +01:00
|
|
|
host = builder.host;
|
|
|
|
port = builder.port;
|
|
|
|
|
|
|
|
proxy = builder.proxy;
|
|
|
|
if (proxy != null) {
|
|
|
|
if (builder.socketFactory != null) {
|
|
|
|
throw new IllegalArgumentException("Can not use proxy together with custom socket factory");
|
|
|
|
}
|
|
|
|
socketFactory = proxy.getSocketFactory();
|
|
|
|
} else {
|
|
|
|
socketFactory = builder.socketFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
securityMode = builder.securityMode;
|
|
|
|
keystoreType = builder.keystoreType;
|
|
|
|
keystorePath = builder.keystorePath;
|
|
|
|
pkcs11Library = builder.pkcs11Library;
|
|
|
|
customSSLContext = builder.customSSLContext;
|
|
|
|
enabledSSLProtocols = builder.enabledSSLProtocols;
|
|
|
|
enabledSSLCiphers = builder.enabledSSLCiphers;
|
|
|
|
hostnameVerifier = builder.hostnameVerifier;
|
|
|
|
sendPresence = builder.sendPresence;
|
|
|
|
rosterLoadedAtLogin = builder.rosterLoadedAtLogin;
|
|
|
|
legacySessionDisabled = builder.legacySessionDisabled;
|
|
|
|
rosterStore = builder.rosterStore;
|
|
|
|
debuggerEnabled = builder.debuggerEnabled;
|
2015-01-10 11:18:07 +01:00
|
|
|
allowNullOrEmptyUsername = builder.allowEmptyOrNullUsername;
|
2006-01-17 21:02:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the server name of the target server.
|
|
|
|
*
|
|
|
|
* @return the server name of the target server.
|
|
|
|
*/
|
|
|
|
public String getServiceName() {
|
|
|
|
return serviceName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-01-11 20:01:24 +01:00
|
|
|
* Returns the TLS security mode used when making the connection. By default,
|
|
|
|
* the mode is {@link SecurityMode#enabled}.
|
2006-01-17 21:02:11 +01:00
|
|
|
*
|
2007-01-11 20:01:24 +01:00
|
|
|
* @return the security mode.
|
2006-01-17 21:02:11 +01:00
|
|
|
*/
|
2007-01-11 20:01:24 +01:00
|
|
|
public SecurityMode getSecurityMode() {
|
|
|
|
return securityMode;
|
2006-01-17 21:02:11 +01:00
|
|
|
}
|
|
|
|
|
2007-11-14 17:27:47 +01:00
|
|
|
/**
|
|
|
|
* Retuns the path to the keystore file. The key store file contains the
|
|
|
|
* certificates that may be used to authenticate the client to the server,
|
|
|
|
* in the event the server requests or requires it.
|
|
|
|
*
|
|
|
|
* @return the path to the keystore file.
|
|
|
|
*/
|
|
|
|
public String getKeystorePath() {
|
|
|
|
return keystorePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the keystore type, or <tt>null</tt> if it's not set.
|
|
|
|
*
|
|
|
|
* @return the keystore type.
|
|
|
|
*/
|
|
|
|
public String getKeystoreType() {
|
|
|
|
return keystoreType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-12-27 17:38:25 +01:00
|
|
|
* Returns the PKCS11 library file location, needed when the
|
2007-11-30 20:40:31 +01:00
|
|
|
* Keystore type is PKCS11.
|
2007-11-14 17:27:47 +01:00
|
|
|
*
|
2007-12-27 17:38:25 +01:00
|
|
|
* @return the path to the PKCS11 library file
|
2007-11-14 17:27:47 +01:00
|
|
|
*/
|
2007-12-27 17:38:25 +01:00
|
|
|
public String getPKCS11Library() {
|
|
|
|
return pkcs11Library;
|
2007-11-14 17:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-17 17:01:53 +01:00
|
|
|
* Gets the custom SSLContext previously set with {@link ConnectionConfiguration.Builder#setCustomSSLContext(SSLContext)} for
|
2014-04-29 22:48:05 +02:00
|
|
|
* SSL sockets. This is null by default.
|
2013-02-26 09:44:17 +01:00
|
|
|
*
|
2014-04-29 22:48:05 +02:00
|
|
|
* @return the custom SSLContext or null.
|
2013-02-26 09:44:17 +01:00
|
|
|
*/
|
|
|
|
public SSLContext getCustomSSLContext() {
|
|
|
|
return this.customSSLContext;
|
|
|
|
}
|
|
|
|
|
2014-05-29 09:21:04 +02:00
|
|
|
/**
|
|
|
|
* Return the enabled SSL/TLS protocols.
|
|
|
|
*
|
|
|
|
* @return the enabled SSL/TLS protocols
|
|
|
|
*/
|
|
|
|
public String[] getEnabledSSLProtocols() {
|
|
|
|
return enabledSSLProtocols;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the enabled SSL/TLS ciphers.
|
|
|
|
*
|
|
|
|
* @return the enabled SSL/TLS ciphers
|
|
|
|
*/
|
|
|
|
public String[] getEnabledSSLCiphers() {
|
|
|
|
return enabledSSLCiphers;
|
|
|
|
}
|
|
|
|
|
2014-07-21 18:42:44 +02:00
|
|
|
/**
|
|
|
|
* Returns the configured HostnameVerifier of this ConnectionConfiguration or the Smack default
|
|
|
|
* HostnameVerifier configured with
|
|
|
|
* {@link SmackConfiguration#setDefaultHostnameVerifier(HostnameVerifier)}.
|
|
|
|
*
|
|
|
|
* @return a configured HostnameVerifier or <code>null</code>
|
|
|
|
*/
|
|
|
|
public HostnameVerifier getHostnameVerifier() {
|
|
|
|
if (hostnameVerifier != null)
|
|
|
|
return hostnameVerifier;
|
|
|
|
return SmackConfiguration.getDefaultHostnameVerifier();
|
|
|
|
}
|
|
|
|
|
2006-01-17 21:02:11 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the new connection about to be establish is going to be debugged. By
|
2014-04-03 13:06:43 +02:00
|
|
|
* default the value of {@link SmackConfiguration#DEBUG_ENABLED} is used.
|
2006-01-17 21:02:11 +01:00
|
|
|
*
|
|
|
|
* @return true if the new connection about to be establish is going to be debugged.
|
|
|
|
*/
|
|
|
|
public boolean isDebuggerEnabled() {
|
|
|
|
return debuggerEnabled;
|
|
|
|
}
|
|
|
|
|
2008-10-24 07:17:50 +02:00
|
|
|
/**
|
|
|
|
* Returns true if the roster will be loaded from the server when logging in. This
|
|
|
|
* is the common behaviour for clients but sometimes clients may want to differ this
|
|
|
|
* or just never do it if not interested in rosters.
|
|
|
|
*
|
|
|
|
* @return true if the roster will be loaded from the server when logging in.
|
|
|
|
*/
|
|
|
|
public boolean isRosterLoadedAtLogin() {
|
|
|
|
return rosterLoadedAtLogin;
|
|
|
|
}
|
|
|
|
|
2014-03-15 14:47:55 +01:00
|
|
|
/**
|
|
|
|
* Returns true if a {@link Session} will be requested on login if the server
|
|
|
|
* supports it. Although this was mandatory on RFC 3921, RFC 6120/6121 don't
|
|
|
|
* even mention this part of the protocol.
|
|
|
|
*
|
|
|
|
* @return true if a session has to be requested when logging in.
|
|
|
|
*/
|
|
|
|
public boolean isLegacySessionDisabled() {
|
|
|
|
return legacySessionDisabled;
|
|
|
|
}
|
|
|
|
|
2008-10-24 07:17:50 +02:00
|
|
|
/**
|
|
|
|
* Returns a CallbackHandler to obtain information, such as the password or
|
|
|
|
* principal information during the SASL authentication. A CallbackHandler
|
|
|
|
* will be used <b>ONLY</b> if no password was specified during the login while
|
|
|
|
* using SASL authentication.
|
|
|
|
*
|
|
|
|
* @return a CallbackHandler to obtain information, such as the password or
|
|
|
|
* principal information during the SASL authentication.
|
|
|
|
*/
|
|
|
|
public CallbackHandler getCallbackHandler() {
|
|
|
|
return callbackHandler;
|
|
|
|
}
|
|
|
|
|
2006-09-14 21:16:40 +02:00
|
|
|
/**
|
|
|
|
* Returns the socket factory used to create new xmppConnection sockets.
|
2007-01-11 20:01:24 +01:00
|
|
|
* This is useful when connecting through SOCKS5 proxies.
|
2006-09-14 21:16:40 +02:00
|
|
|
*
|
|
|
|
* @return socketFactory used to create new sockets.
|
|
|
|
*/
|
|
|
|
public SocketFactory getSocketFactory() {
|
|
|
|
return this.socketFactory;
|
|
|
|
}
|
2006-11-10 20:06:33 +01:00
|
|
|
|
2013-11-10 15:02:57 +01:00
|
|
|
/**
|
|
|
|
* Get the permanent roster store
|
|
|
|
*/
|
|
|
|
public RosterStore getRosterStore() {
|
|
|
|
return rosterStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-11 20:01:24 +01:00
|
|
|
/**
|
|
|
|
* An enumeration for TLS security modes that are available when making a connection
|
|
|
|
* to the XMPP server.
|
|
|
|
*/
|
|
|
|
public static enum SecurityMode {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Securirty via TLS encryption is required in order to connect. If the server
|
|
|
|
* does not offer TLS or if the TLS negotiaton fails, the connection to the server
|
|
|
|
* will fail.
|
|
|
|
*/
|
|
|
|
required,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Security via TLS encryption is used whenever it's available. This is the
|
|
|
|
* default setting.
|
|
|
|
*/
|
|
|
|
enabled,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Security via TLS encryption is disabled and only un-encrypted connections will
|
|
|
|
* be used. If only TLS encryption is available from the server, the connection
|
|
|
|
* will fail.
|
|
|
|
*/
|
|
|
|
disabled
|
2006-09-14 21:16:40 +02:00
|
|
|
}
|
2006-11-10 20:06:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the username to use when trying to reconnect to the server.
|
|
|
|
*
|
|
|
|
* @return the username to use when trying to reconnect to the server.
|
2006-09-14 21:16:40 +02:00
|
|
|
*/
|
2014-04-10 21:12:12 +02:00
|
|
|
public String getUsername() {
|
2006-09-14 21:16:40 +02:00
|
|
|
return this.username;
|
|
|
|
}
|
2006-11-10 20:06:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the password to use when trying to reconnect to the server.
|
|
|
|
*
|
|
|
|
* @return the password to use when trying to reconnect to the server.
|
2006-09-14 21:16:40 +02:00
|
|
|
*/
|
2014-04-10 21:12:12 +02:00
|
|
|
public String getPassword() {
|
2006-09-14 21:16:40 +02:00
|
|
|
return this.password;
|
|
|
|
}
|
2006-11-10 20:06:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the resource to use when trying to reconnect to the server.
|
|
|
|
*
|
|
|
|
* @return the resource to use when trying to reconnect to the server.
|
|
|
|
*/
|
2014-04-10 21:12:12 +02:00
|
|
|
public String getResource() {
|
2006-11-10 20:06:33 +01:00
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if an available presence should be sent when logging in while reconnecting.
|
|
|
|
*
|
|
|
|
* @return true if an available presence should be sent when logging in while reconnecting
|
|
|
|
*/
|
2014-04-10 21:12:12 +02:00
|
|
|
public boolean isSendPresence() {
|
2006-11-10 20:06:33 +01:00
|
|
|
return sendPresence;
|
|
|
|
}
|
2007-01-11 20:01:24 +01:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the connection is going to use stream compression. Stream compression
|
|
|
|
* will be requested after TLS was established (if TLS was enabled) and only if the server
|
|
|
|
* offered stream compression. With stream compression network traffic can be reduced
|
|
|
|
* up to 90%. By default compression is disabled.
|
|
|
|
*
|
|
|
|
* @return true if the connection is going to use stream compression.
|
|
|
|
*/
|
|
|
|
public boolean isCompressionEnabled() {
|
|
|
|
// Compression for non-TCP connections is always disabled
|
|
|
|
return false;
|
2007-01-11 20:01:24 +01:00
|
|
|
}
|
2013-03-18 09:53:11 +01:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
/**
|
|
|
|
* A builder for XMPP connection configurations.
|
|
|
|
* <p>
|
|
|
|
* This is an abstract class that uses the builder design pattern and the "getThis() trick" to recover the type of
|
|
|
|
* the builder in a class hierarchies with a self-referential generic supertype. Otherwise chaining of build
|
|
|
|
* instructions from the superclasses followed by build instructions of a sublcass would not be possible, because
|
|
|
|
* the superclass build instructions would return the builder of the superclass and not the one of the subclass. You
|
|
|
|
* can read more about it a Angelika Langer's Generics FAQ, especially the entry <a
|
|
|
|
* href="http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206">What is the
|
|
|
|
* "getThis()" trick?</a>.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param <B> the builder type parameter.
|
|
|
|
* @param <C> the resulting connection configuration type parameter.
|
|
|
|
*/
|
2014-12-17 17:01:53 +01:00
|
|
|
public static abstract class Builder<B extends Builder<B, C>, C extends ConnectionConfiguration> {
|
2014-11-09 18:30:16 +01:00
|
|
|
private SecurityMode securityMode = SecurityMode.enabled;
|
|
|
|
private String keystorePath = System.getProperty("javax.net.ssl.keyStore");
|
|
|
|
private String keystoreType = "jks";
|
|
|
|
private String pkcs11Library = "pkcs11.config";
|
|
|
|
private SSLContext customSSLContext;
|
|
|
|
private String[] enabledSSLProtocols;
|
|
|
|
private String[] enabledSSLCiphers;
|
|
|
|
private HostnameVerifier hostnameVerifier;
|
|
|
|
private String username;
|
|
|
|
private String password;
|
|
|
|
private String resource = "Smack";
|
|
|
|
private boolean sendPresence = true;
|
|
|
|
private boolean rosterLoadedAtLogin = true;
|
|
|
|
private boolean legacySessionDisabled = false;
|
|
|
|
private RosterStore rosterStore;
|
|
|
|
private ProxyInfo proxy;
|
|
|
|
private CallbackHandler callbackHandler;
|
|
|
|
private boolean debuggerEnabled = SmackConfiguration.DEBUG_ENABLED;
|
|
|
|
private SocketFactory socketFactory;
|
|
|
|
private String serviceName;
|
|
|
|
private String host;
|
|
|
|
private int port = 5222;
|
2015-01-10 11:18:07 +01:00
|
|
|
private boolean allowEmptyOrNullUsername = false;
|
2014-11-09 18:30:16 +01:00
|
|
|
|
2014-12-17 17:01:53 +01:00
|
|
|
protected Builder() {
|
2014-11-09 18:30:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the XMPP entities username and password.
|
|
|
|
* <p>
|
2014-12-18 14:01:31 +01:00
|
|
|
* The username is the localpart of the entities JID, e.g. <code>localpart@example.org</code>.
|
2014-11-09 18:30:16 +01:00
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param username
|
|
|
|
* @param password
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setUsernameAndPassword(String username, String password) {
|
|
|
|
this.username = username;
|
|
|
|
this.password = password;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the service name of this XMPP service (i.e., the XMPP domain).
|
|
|
|
*
|
|
|
|
* @param serviceName the service name
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setServiceName(String serviceName) {
|
|
|
|
this.serviceName = serviceName;
|
|
|
|
return getThis();
|
|
|
|
}
|
2014-03-18 17:29:38 +01:00
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
/**
|
|
|
|
* Set the resource to use.
|
|
|
|
* <p>
|
|
|
|
* If <code>resource</code> is <code>null</code>, then the server will automatically create a resource for the
|
|
|
|
* client. Default resource is "Smack".
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param resource the resource to use.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setResource(String resource) {
|
|
|
|
this.resource = resource;
|
|
|
|
return getThis();
|
2014-08-01 23:20:35 +02:00
|
|
|
}
|
2014-11-09 18:30:16 +01:00
|
|
|
|
|
|
|
public B setHost(String host) {
|
|
|
|
this.host = host;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
public B setPort(int port) {
|
|
|
|
this.port = port;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a CallbackHandler to obtain information, such as the password or
|
|
|
|
* principal information during the SASL authentication. A CallbackHandler
|
|
|
|
* will be used <b>ONLY</b> if no password was specified during the login while
|
|
|
|
* using SASL authentication.
|
|
|
|
*
|
|
|
|
* @param callbackHandler to obtain information, such as the password or
|
|
|
|
* principal information during the SASL authentication.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setCallbackHandler(CallbackHandler callbackHandler) {
|
|
|
|
this.callbackHandler = callbackHandler;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the TLS security mode used when making the connection. By default,
|
|
|
|
* the mode is {@link SecurityMode#enabled}.
|
|
|
|
*
|
|
|
|
* @param securityMode the security mode.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setSecurityMode(SecurityMode securityMode) {
|
|
|
|
this.securityMode = securityMode;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the path to the keystore file. The key store file contains the
|
|
|
|
* certificates that may be used to authenticate the client to the server,
|
|
|
|
* in the event the server requests or requires it.
|
|
|
|
*
|
|
|
|
* @param keystorePath the path to the keystore file.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setKeystorePath(String keystorePath) {
|
|
|
|
this.keystorePath = keystorePath;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the keystore type.
|
|
|
|
*
|
|
|
|
* @param keystoreType the keystore type.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setKeystoreType(String keystoreType) {
|
|
|
|
this.keystoreType = keystoreType;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the PKCS11 library file location, needed when the
|
|
|
|
* Keystore type is PKCS11
|
|
|
|
*
|
|
|
|
* @param pkcs11Library the path to the PKCS11 library file.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setPKCS11Library(String pkcs11Library) {
|
|
|
|
this.pkcs11Library = pkcs11Library;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a custom SSLContext for creating SSL sockets.
|
|
|
|
* <p>
|
|
|
|
* For more information on how to create a SSLContext see <a href=
|
|
|
|
* "http://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#X509TrustManager"
|
|
|
|
* >Java Secure Socket Extension (JSEE) Reference Guide: Creating Your Own X509TrustManager</a>
|
|
|
|
*
|
|
|
|
* @param context the custom SSLContext for new sockets.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setCustomSSLContext(SSLContext context) {
|
|
|
|
this.customSSLContext = context;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the enabled SSL/TLS protocols.
|
|
|
|
*
|
|
|
|
* @param enabledSSLProtocols
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setEnabledSSLProtocols(String[] enabledSSLProtocols) {
|
|
|
|
this.enabledSSLProtocols = enabledSSLProtocols;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the enabled SSL/TLS ciphers.
|
|
|
|
*
|
|
|
|
* @param enabledSSLCiphers the enabled SSL/TLS ciphers
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setEnabledSSLCiphers(String[] enabledSSLCiphers) {
|
|
|
|
this.enabledSSLCiphers = enabledSSLCiphers;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the HostnameVerifier used to verify the hostname of SSLSockets used by XMPP connections
|
|
|
|
* created with this ConnectionConfiguration.
|
|
|
|
*
|
|
|
|
* @param verifier
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setHostnameVerifier(HostnameVerifier verifier) {
|
|
|
|
hostnameVerifier = verifier;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if a {@link Session} will be requested on login if the server supports
|
|
|
|
* it. Although this was mandatory on RFC 3921, RFC 6120/6121 don't even
|
|
|
|
* mention this part of the protocol.
|
|
|
|
*
|
|
|
|
* @param legacySessionDisabled if a session has to be requested when logging in.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setLegacySessionDisabled(boolean legacySessionDisabled) {
|
|
|
|
this.legacySessionDisabled = legacySessionDisabled;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if the roster will be loaded from the server when logging in. This
|
|
|
|
* is the common behaviour for clients but sometimes clients may want to differ this
|
|
|
|
* or just never do it if not interested in rosters.
|
|
|
|
*
|
|
|
|
* @param rosterLoadedAtLogin if the roster will be loaded from the server when logging in.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setRosterLoadedAtLogin(boolean rosterLoadedAtLogin) {
|
|
|
|
this.rosterLoadedAtLogin = rosterLoadedAtLogin;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if an initial available presence will be sent to the server. By default
|
|
|
|
* an available presence will be sent to the server indicating that this presence
|
|
|
|
* is not online and available to receive messages. If you want to log in without
|
|
|
|
* being 'noticed' then pass a <tt>false</tt> value.
|
|
|
|
*
|
|
|
|
* @param sendPresence true if an initial available presence will be sent while logging in.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setSendPresence(boolean sendPresence) {
|
|
|
|
this.sendPresence = sendPresence;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the permanent roster store.
|
|
|
|
*
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setRosterStore(RosterStore store) {
|
|
|
|
rosterStore = store;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if the new connection about to be establish is going to be debugged. By
|
|
|
|
* default the value of {@link SmackConfiguration#DEBUG_ENABLED} is used.
|
|
|
|
*
|
|
|
|
* @param debuggerEnabled if the new connection about to be establish is going to be debugged.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setDebuggerEnabled(boolean debuggerEnabled) {
|
|
|
|
this.debuggerEnabled = debuggerEnabled;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the socket factory used to create new xmppConnection sockets.
|
|
|
|
* This is useful when connecting through SOCKS5 proxies.
|
|
|
|
*
|
|
|
|
* @param socketFactory used to create new sockets.
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B setSocketFactory(SocketFactory socketFactory) {
|
|
|
|
this.socketFactory = socketFactory;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
2015-01-10 11:18:07 +01:00
|
|
|
/**
|
|
|
|
* Allow <code>null</code> or the empty String as username.
|
|
|
|
*
|
|
|
|
* Some SASL mechanisms (e.g. SASL External) may also signal the username (as "authorization identity"), in
|
|
|
|
* which case Smack should not throw an IllegalArgumentException when the username is not set.
|
|
|
|
*
|
|
|
|
* @return a reference to this builder.
|
|
|
|
*/
|
|
|
|
public B allowEmptyOrNullUsernames() {
|
|
|
|
allowEmptyOrNullUsername = true;
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
2014-11-09 18:30:16 +01:00
|
|
|
public abstract C build();
|
|
|
|
|
|
|
|
protected abstract B getThis();
|
2013-03-18 09:53:11 +01:00
|
|
|
}
|
2007-11-14 17:27:47 +01:00
|
|
|
}
|