Class ConnectionConfiguration.Builder<B extends ConnectionConfiguration.Builder<B,C>,C extends ConnectionConfiguration>
- java.lang.Object
-
- org.jivesoftware.smack.ConnectionConfiguration.Builder<B,C>
-
- Type Parameters:
B
- the builder type parameter.C
- the resulting connection configuration type parameter.
- Direct Known Subclasses:
BOSHConfiguration.Builder
,ModularXmppClientToServerConnectionConfiguration.Builder
,XMPPTCPConnectionConfiguration.Builder
- Enclosing class:
- ConnectionConfiguration
public abstract static class ConnectionConfiguration.Builder<B extends ConnectionConfiguration.Builder<B,C>,C extends ConnectionConfiguration> extends java.lang.Object
A builder for XMPP connection configurations.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 subclass 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 What is the "getThis()" trick?.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description B
addEnabledSaslMechanism(java.lang.String saslMechanism)
Add the given mechanism to the enabled ones.B
addEnabledSaslMechanism(java.util.Collection<java.lang.String> saslMechanisms)
Enable the given SASL mechanisms.B
allowEmptyOrNullUsernames()
Allownull
or the empty String as username.abstract C
build()
B
enableDefaultDebugger()
static javax.net.ssl.KeyManager[]
getKeyManagersFrom(java.lang.String keystoreType, java.lang.String keystorePath, javax.security.auth.callback.CallbackHandler callbackHandler, java.lang.String pkcs11Library)
protected abstract B
getThis()
B
performSaslAnonymousAuthentication()
Perform anonymous authentication using SASL ANONYMOUS.B
performSaslExternalAuthentication(javax.net.ssl.SSLContext sslContext)
Perform authentication using SASL EXTERNAL.B
setAuthzid(EntityBareJid authzid)
Set the XMPP address to be used as authorization identity.B
setCallbackHandler(javax.security.auth.callback.CallbackHandler callbackHandler)
Deprecated.set a callback-handler awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.B
setCompressionEnabled(boolean compressionEnabled)
Sets if the connection is going to use compression (default false).B
setCustomSSLContext(javax.net.ssl.SSLContext context)
Deprecated.usesetSslContextFactory(SslContextFactory)
instead}.B
setCustomX509TrustManager(javax.net.ssl.X509TrustManager x509TrustManager)
B
setDebuggerFactory(SmackDebuggerFactory debuggerFactory)
Set the Smack debugger factory used to construct Smack debuggers.B
setDnssecMode(ConnectionConfiguration.DnssecMode dnssecMode)
B
setEnabledSSLCiphers(java.lang.String[] enabledSSLCiphers)
Set the enabled SSL/TLS ciphers.B
setEnabledSSLProtocols(java.lang.String[] enabledSSLProtocols)
Set the enabled SSL/TLS protocols.B
setHost(java.lang.CharSequence host)
Set the name of the host providing the XMPP service.B
setHost(DnsName host)
Set the name of the host providing the XMPP service.B
setHostAddress(java.net.InetAddress address)
Set the Internet address of the host providing the XMPP service.B
setHostAddressByNameOrIp(java.lang.CharSequence fqdnOrIp)
Deprecated.usesetHost(CharSequence)
instead.B
setHostnameVerifier(javax.net.ssl.HostnameVerifier verifier)
Set the HostnameVerifier used to verify the hostname of SSLSockets used by XMPP connections created with this ConnectionConfiguration.B
setKeyManager(javax.net.ssl.KeyManager keyManager)
Set theKeyManager
s to initialize theSSLContext
used by Smack to establish the XMPP connection.B
setKeyManagers(javax.net.ssl.KeyManager[] keyManagers)
Set theKeyManager
s to initialize theSSLContext
used by Smack to establish the XMPP connection.B
setKeystorePath(java.lang.String keystorePath)
Deprecated.set a keystore-path awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.B
setKeystoreType(java.lang.String keystoreType)
Deprecated.set a key-type awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.B
setLanguage(java.util.Locale language)
Set the stream language.B
setPKCS11Library(java.lang.String pkcs11Library)
Deprecated.set a PKCS11-library awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.B
setPort(int port)
B
setPort(UInt16 port)
B
setProxyInfo(ProxyInfo proxyInfo)
Set the information about the Proxy used for the connection.B
setResource(java.lang.CharSequence resource)
Set the resource we are requesting from the server.B
setResource(Resourcepart resource)
Set the resource we are requesting from the server.B
setSecurityMode(ConnectionConfiguration.SecurityMode securityMode)
Sets the TLS security mode used when making the connection.B
setSendPresence(boolean sendPresence)
Sets if an initial available presence will be sent to the server.B
setServiceName(DomainBareJid serviceName)
Deprecated.usesetXmppDomain(DomainBareJid)
instead.B
setSocketFactory(javax.net.SocketFactory socketFactory)
Sets the socket factory used to create new xmppConnection sockets.B
setSslContextFactory(SslContextFactory sslContextFactory)
Sets a custom SSLContext for creating SSL sockets.B
setSslContextSecureRandom(java.security.SecureRandom secureRandom)
Set theSecureRandom
used to initialize theSSLContext
used by Smack to establish the XMPP connection.B
setStanzaIdSourceFactory(StanzaIdSourceFactory stanzaIdSourceFactory)
Set the factory for stanza ID sources to use.B
setUsernameAndPassword(java.lang.CharSequence username, java.lang.String password)
Set the XMPP entities username and password.B
setXmppAddressAndPassword(java.lang.CharSequence jid, java.lang.String password)
Convenience method to configure the username, password and XMPP service domain.B
setXmppAddressAndPassword(EntityBareJid jid, java.lang.String password)
Convenience method to configure the username, password and XMPP service domain.B
setXmppDomain(java.lang.String xmppServiceDomain)
Set the XMPP domain.B
setXmppDomain(DomainBareJid xmppDomain)
Set the XMPP domain.
-
-
-
Constructor Detail
-
Builder
protected Builder()
-
-
Method Detail
-
setXmppAddressAndPassword
public B setXmppAddressAndPassword(java.lang.CharSequence jid, java.lang.String password) throws XmppStringprepException
Convenience method to configure the username, password and XMPP service domain.- Parameters:
jid
- the XMPP address of the user.password
- the password of the user.- Returns:
- a reference to this builder.
- Throws:
XmppStringprepException
- in case the XMPP address is not valid.- Since:
- 4.4.0
- See Also:
setXmppAddressAndPassword(EntityBareJid, String)
-
setXmppAddressAndPassword
public B setXmppAddressAndPassword(EntityBareJid jid, java.lang.String password)
Convenience method to configure the username, password and XMPP service domain. The localpart of the provided JID is used as username and the domanipart is used as XMPP service domain.Please note that this does and can not configure the client XMPP address. XMPP services are not required to assign bound JIDs where the localpart matches the username and the domainpart matches the verified domainpart. Although most services will follow that pattern.
- Parameters:
jid
- TODO javadoc me pleasepassword
- TODO javadoc me please- Returns:
- a reference to this builder.
- Since:
- 4.4.0
-
setUsernameAndPassword
public B setUsernameAndPassword(java.lang.CharSequence username, java.lang.String password)
Set the XMPP entities username and password.The username is usually the localpart of the clients JID. But some SASL mechanisms or services may require a different format (e.g. the full JID) as used authorization identity.
- Parameters:
username
- the username or authorization identitypassword
- the password or token used to authenticate- Returns:
- a reference to this builder.
-
setServiceName
@Deprecated public B setServiceName(DomainBareJid serviceName)
Deprecated.usesetXmppDomain(DomainBareJid)
instead.Set the XMPP domain. The XMPP domain is what follows after the '@' sign in XMPP addresses (JIDs).- Parameters:
serviceName
- the service name- Returns:
- a reference to this builder.
-
setXmppDomain
public B setXmppDomain(DomainBareJid xmppDomain)
Set the XMPP domain. The XMPP domain is what follows after the '@' sign in XMPP addresses (JIDs).- Parameters:
xmppDomain
- the XMPP domain.- Returns:
- a reference to this builder.
-
setXmppDomain
public B setXmppDomain(java.lang.String xmppServiceDomain) throws XmppStringprepException
Set the XMPP domain. The XMPP domain is what follows after the '@' sign in XMPP addresses (JIDs).- Parameters:
xmppServiceDomain
- the XMPP domain.- Returns:
- a reference to this builder.
- Throws:
XmppStringprepException
- if the given string is not a domain bare JID.
-
setResource
public B setResource(Resourcepart resource)
Set the resource we are requesting from the server.If
resource
isnull
, the default, then the server will automatically create a resource for the client. Note that XMPP clients only suggest this resource to the server. XMPP servers are allowed to ignore the client suggested resource and instead assign a completely different resource (see RFC 6120 § 7.7.1).- Parameters:
resource
- the resource to use.- Returns:
- a reference to this builder.
- See Also:
- RFC 6120 § 7.7.1
-
setLanguage
public B setLanguage(java.util.Locale language)
Set the stream language.- Parameters:
language
- the language to use.- Returns:
- a reference to this builder.
- See Also:
- RFC 6120 § 4.7.4, XML 1.0 § 2.12 Language Identification
-
setResource
public B setResource(java.lang.CharSequence resource) throws XmppStringprepException
Set the resource we are requesting from the server.- Parameters:
resource
- the non-null CharSequence to use a resource.- Returns:
- a reference ot this builder.
- Throws:
XmppStringprepException
- if the CharSequence is not a valid resourcepart.- See Also:
setResource(Resourcepart)
-
setHostAddress
public B setHostAddress(java.net.InetAddress address)
Set the Internet address of the host providing the XMPP service. If set, then this will overwrite anything set viasetHost(CharSequence)
.- Parameters:
address
- the Internet address of the host providing the XMPP service.- Returns:
- a reference to this builder.
- Since:
- 4.2
-
setHost
public B setHost(java.lang.CharSequence host)
Set the name of the host providing the XMPP service. This method takes DNS names and IP addresses.- Parameters:
host
- the DNS name of the host providing the XMPP service.- Returns:
- a reference to this builder.
-
setHost
public B setHost(DnsName host)
Set the name of the host providing the XMPP service. Note that this method does only allow DNS names and not IP addresses. UsesetHostAddress(InetAddress)
if you want to explicitly set the Internet address of the host providing the XMPP service.- Parameters:
host
- the DNS name of the host providing the XMPP service.- Returns:
- a reference to this builder.
-
setHostAddressByNameOrIp
@Deprecated public B setHostAddressByNameOrIp(java.lang.CharSequence fqdnOrIp)
Deprecated.usesetHost(CharSequence)
instead.Set the host to connect to by either its fully qualified domain name (FQDN) or its IP.- Parameters:
fqdnOrIp
- a CharSequence either representing the FQDN or the IP of the host.- Returns:
- a reference to this builder.
- Since:
- 4.3.2
- See Also:
setHost(DnsName)
,setHostAddress(InetAddress)
-
setCallbackHandler
@Deprecated public B setCallbackHandler(javax.security.auth.callback.CallbackHandler callbackHandler)
Deprecated.set a callback-handler awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.Sets a CallbackHandler to obtain information, such as the password or principal information during the SASL authentication. A CallbackHandler will be used ONLY if no password was specified during the login while using SASL authentication.- Parameters:
callbackHandler
- to obtain information, such as the password or principal information during the SASL authentication.- Returns:
- a reference to this builder.
-
setDnssecMode
public B setDnssecMode(ConnectionConfiguration.DnssecMode dnssecMode)
-
setCustomX509TrustManager
public B setCustomX509TrustManager(javax.net.ssl.X509TrustManager x509TrustManager)
-
setSecurityMode
public B setSecurityMode(ConnectionConfiguration.SecurityMode securityMode)
Sets the TLS security mode used when making the connection. By default, the mode isConnectionConfiguration.SecurityMode.required
.- Parameters:
securityMode
- the security mode.- Returns:
- a reference to this builder.
-
setKeyManagers
public B setKeyManagers(javax.net.ssl.KeyManager[] keyManagers)
Set theKeyManager
s to initialize theSSLContext
used by Smack to establish the XMPP connection.- Parameters:
keyManagers
- an array ofKeyManager
s to initialize theSSLContext
with.- Returns:
- a reference to this builder.
- Since:
- 4.4.5
-
setKeyManager
public B setKeyManager(javax.net.ssl.KeyManager keyManager)
Set theKeyManager
s to initialize theSSLContext
used by Smack to establish the XMPP connection.- Parameters:
keyManager
- theKeyManager
s to initialize theSSLContext
with.- Returns:
- a reference to this builder.
- Since:
- 4.4.5
- See Also:
setKeyManagers(KeyManager[])
-
setSslContextSecureRandom
public B setSslContextSecureRandom(java.security.SecureRandom secureRandom)
Set theSecureRandom
used to initialize theSSLContext
used by Smack to establish the XMPP connection. Note that you usually do not need (nor want) to set this. Because if theSecureRandom
is not explicitly set, Smack will initialize theSSLContext
withnull
asSecureRandom
argument. And all saneSSLContext
implementations will then select a safe secure random source by default.- Parameters:
secureRandom
- theSecureRandom
to initialize theSSLContext
with.- Returns:
- a reference to this builder.
- Since:
- 4.4.5
-
setKeystorePath
@Deprecated public B setKeystorePath(java.lang.String keystorePath)
Deprecated.set a keystore-path awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.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.- Parameters:
keystorePath
- the path to the keystore file.- Returns:
- a reference to this builder.
-
setKeystoreType
@Deprecated public B setKeystoreType(java.lang.String keystoreType)
Deprecated.set a key-type awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.Sets the keystore type.- Parameters:
keystoreType
- the keystore type.- Returns:
- a reference to this builder.
-
setPKCS11Library
@Deprecated public B setPKCS11Library(java.lang.String pkcs11Library)
Deprecated.set a PKCS11-library awareKeyManager
viasetKeyManager(KeyManager)
orsetKeyManagers(KeyManager[])
, created bygetKeyManagersFrom(String, String, CallbackHandler, String)
, instead.Sets the PKCS11 library file location, needed when the Keystore type is PKCS11.- Parameters:
pkcs11Library
- the path to the PKCS11 library file.- Returns:
- a reference to this builder.
-
setCustomSSLContext
@Deprecated public B setCustomSSLContext(javax.net.ssl.SSLContext context)
Deprecated.usesetSslContextFactory(SslContextFactory)
instead}.Sets a custom SSLContext for creating SSL sockets.For more information on how to create a SSLContext see Java Secure Socket Extension (JSEE) Reference Guide: Creating Your Own X509TrustManager
- Parameters:
context
- the custom SSLContext for new sockets.- Returns:
- a reference to this builder.
-
setSslContextFactory
public B setSslContextFactory(SslContextFactory sslContextFactory)
Sets a custom SSLContext for creating SSL sockets.For more information on how to create a SSLContext see Java Secure Socket Extension (JSEE) Reference Guide: Creating Your Own X509TrustManager
- Parameters:
sslContextFactory
- the custom SSLContext for new sockets.- Returns:
- a reference to this builder.
-
setEnabledSSLProtocols
public B setEnabledSSLProtocols(java.lang.String[] enabledSSLProtocols)
Set the enabled SSL/TLS protocols.- Parameters:
enabledSSLProtocols
- TODO javadoc me please- Returns:
- a reference to this builder.
-
setEnabledSSLCiphers
public B setEnabledSSLCiphers(java.lang.String[] enabledSSLCiphers)
Set the enabled SSL/TLS ciphers.- Parameters:
enabledSSLCiphers
- the enabled SSL/TLS ciphers- Returns:
- a reference to this builder.
-
setHostnameVerifier
public B setHostnameVerifier(javax.net.ssl.HostnameVerifier verifier)
Set the HostnameVerifier used to verify the hostname of SSLSockets used by XMPP connections created with this ConnectionConfiguration.- Parameters:
verifier
- TODO javadoc me please- Returns:
- a reference to this builder.
-
setSendPresence
public B setSendPresence(boolean sendPresence)
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 afalse
value.- Parameters:
sendPresence
- true if an initial available presence will be sent while logging in.- Returns:
- a reference to this builder.
-
enableDefaultDebugger
public B enableDefaultDebugger()
-
setDebuggerFactory
public B setDebuggerFactory(SmackDebuggerFactory debuggerFactory)
Set the Smack debugger factory used to construct Smack debuggers.- Parameters:
debuggerFactory
- the Smack debugger factory.- Returns:
- a reference to this builder.
-
setSocketFactory
public B setSocketFactory(javax.net.SocketFactory socketFactory)
Sets the socket factory used to create new xmppConnection sockets. This is useful when connecting through SOCKS5 proxies.- Parameters:
socketFactory
- used to create new sockets.- Returns:
- a reference to this builder.
-
setProxyInfo
public B setProxyInfo(ProxyInfo proxyInfo)
Set the information about the Proxy used for the connection.- Parameters:
proxyInfo
- the Proxy information.- Returns:
- a reference to this builder.
-
allowEmptyOrNullUsernames
public B allowEmptyOrNullUsernames()
Allownull
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.- Returns:
- a reference to this builder.
-
performSaslAnonymousAuthentication
public B performSaslAnonymousAuthentication()
Perform anonymous authentication using SASL ANONYMOUS. Your XMPP service must support this authentication mechanism. This method also callsaddEnabledSaslMechanism(String)
with "ANONYMOUS" as argument.- Returns:
- a reference to this builder.
-
performSaslExternalAuthentication
public B performSaslExternalAuthentication(javax.net.ssl.SSLContext sslContext)
Perform authentication using SASL EXTERNAL. Your XMPP service must support this authentication mechanism. This method also callsaddEnabledSaslMechanism(String)
with "EXTERNAL" as argument. It also callsallowEmptyOrNullUsernames()
andsetSecurityMode(ConnectionConfiguration.SecurityMode)
toConnectionConfiguration.SecurityMode.required
.- Parameters:
sslContext
- custom SSLContext to be used.- Returns:
- a reference to this builder.
-
addEnabledSaslMechanism
public B addEnabledSaslMechanism(java.lang.String saslMechanism)
Add the given mechanism to the enabled ones. SeeaddEnabledSaslMechanism(Collection)
for a discussion about enabled SASL mechanisms.- Parameters:
saslMechanism
- the name of the mechanism to enable.- Returns:
- a reference to this builder.
-
addEnabledSaslMechanism
public B addEnabledSaslMechanism(java.util.Collection<java.lang.String> saslMechanisms)
Enable the given SASL mechanisms. If you never add a mechanism to the set of enabled ones, all mechanisms known to Smack will be enabled. Only explicitly enable particular SASL mechanisms if you want to limit the used mechanisms to the enabled ones.- Parameters:
saslMechanisms
- a collection of names of mechanisms to enable.- Returns:
- a reference to this builder.
-
setAuthzid
public B setAuthzid(EntityBareJid authzid)
Set the XMPP address to be used as authorization identity.In XMPP, authorization identities are bare jids. In general, callers should allow the server to select the authorization identifier automatically, and not call this. Note that setting the authzid does not set the XMPP service domain, which should typically match. Calling this will also SASL CRAM, since this mechanism does not support authzid.
- Parameters:
authzid
- The BareJid to be requested as the authorization identifier.- Returns:
- a reference to this builder.
- Since:
- 4.2
- See Also:
- RFC 6120 § 6.3.8. Authorization Identity
-
setCompressionEnabled
public B setCompressionEnabled(boolean compressionEnabled)
Sets if the connection is going to use compression (default false). Compression is only activated if the server offers compression. With compression network traffic can be reduced up to 90%. By default compression is disabled.- Parameters:
compressionEnabled
- if the connection is going to use compression on the HTTP level.- Returns:
- a reference to this object.
-
setStanzaIdSourceFactory
public B setStanzaIdSourceFactory(StanzaIdSourceFactory stanzaIdSourceFactory)
Set the factory for stanza ID sources to use.- Parameters:
stanzaIdSourceFactory
- the factory for stanza ID sources to use.- Returns:
- a reference to this builder.
- Since:
- 4.4
-
getKeyManagersFrom
public static javax.net.ssl.KeyManager[] getKeyManagersFrom(java.lang.String keystoreType, java.lang.String keystorePath, javax.security.auth.callback.CallbackHandler callbackHandler, java.lang.String pkcs11Library) throws java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.ClassNotFoundException, java.security.KeyStoreException, java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, javax.security.auth.callback.UnsupportedCallbackException, java.security.UnrecoverableKeyException
- Throws:
java.lang.NoSuchMethodException
java.lang.SecurityException
java.lang.ClassNotFoundException
java.security.KeyStoreException
java.security.NoSuchProviderException
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
javax.security.auth.callback.UnsupportedCallbackException
java.security.UnrecoverableKeyException
-
-