Smack

org.jivesoftware.smack
Class ConnectionConfiguration

java.lang.Object
  extended by org.jivesoftware.smack.ConnectionConfiguration
All Implemented Interfaces:
Cloneable

public class ConnectionConfiguration
extends Object
implements Cloneable

Configuration to use while establishing the connection to the server. It is possible to configure the path to the trustore file that keeps the trusted CA root certificates and enable or disable all or some of the checkings done while verifying server certificates.

It is also possible to configure if TLS, SASL, and compression are used or not.

Author:
Gaston Dombiak

Nested Class Summary
static class ConnectionConfiguration.SecurityMode
          An enumeration for TLS security modes that are available when making a connection to the XMPP server.
 
Field Summary
protected  ProxyInfo proxy
           
 
Constructor Summary
ConnectionConfiguration(String serviceName)
          Creates a new ConnectionConfiguration for the specified service name.
ConnectionConfiguration(String host, int port)
          Creates a new ConnectionConfiguration for a connection that will connect to the desired host and port.
ConnectionConfiguration(String host, int port, ProxyInfo proxy)
          Creates a new ConnectionConfiguration for a connection that will connect to the desired host and port with desired proxy.
ConnectionConfiguration(String host, int port, String serviceName)
          Creates a new ConnectionConfiguration using the specified host, port and service name.
ConnectionConfiguration(String host, int port, String serviceName, ProxyInfo proxy)
          Creates a new ConnectionConfiguration using the specified host, port and service name.
ConnectionConfiguration(String serviceName, ProxyInfo proxy)
          Creates a new ConnectionConfiguration for the specified service name with specified proxy.
 
Method Summary
 javax.security.auth.callback.CallbackHandler getCallbackHandler()
          Returns a CallbackHandler to obtain information, such as the password or principal information during the SASL authentication.
 String getHost()
          Returns the host to use when establishing the connection.
 String getKeystorePath()
          Retuns the path to the keystore file.
 String getKeystoreType()
          Returns the keystore type, or null if it's not set.
 String getPKCS11Library()
          Returns the PKCS11 library file location, needed when the Keystore type is PKCS11.
 int getPort()
          Returns the port to use when establishing the connection.
 ConnectionConfiguration.SecurityMode getSecurityMode()
          Returns the TLS security mode used when making the connection.
 String getServiceName()
          Returns the server name of the target server.
 javax.net.SocketFactory getSocketFactory()
          Returns the socket factory used to create new xmppConnection sockets.
 String getTruststorePassword()
          Returns the password to use to access the trust store file.
 String getTruststorePath()
          Retuns the path to the trust store file.
 String getTruststoreType()
          Returns the trust store type, or null if it's not set.
 boolean isCompressionEnabled()
          Returns true if the connection is going to use stream compression.
 boolean isDebuggerEnabled()
          Returns true if the new connection about to be establish is going to be debugged.
 boolean isExpiredCertificatesCheckEnabled()
          Returns true if certificates presented by the server are going to be checked for their validity.
 boolean isNotMatchingDomainCheckEnabled()
          Returns true if certificates presented by the server are going to be checked for their domain.
 boolean isReconnectionAllowed()
          Returns if the reconnection mechanism is allowed to be used.
 boolean isRosterLoadedAtLogin()
          Returns true if the roster will be loaded from the server when logging in.
 boolean isSASLAuthenticationEnabled()
          Returns true if the client is going to use SASL authentication when logging into the server.
 boolean isSelfSignedCertificateEnabled()
          Returns true if self-signed certificates are going to be accepted.
 boolean isVerifyChainEnabled()
          Returns true if the whole chain of certificates presented by the server are going to be checked.
 boolean isVerifyRootCAEnabled()
          Returns true if root CA checking is going to be done.
 void setCallbackHandler(javax.security.auth.callback.CallbackHandler callbackHandler)
          Sets a CallbackHandler to obtain information, such as the password or principal information during the SASL authentication.
 void setCompressionEnabled(boolean compressionEnabled)
          Sets if the connection is going to use stream compression.
 void setDebuggerEnabled(boolean debuggerEnabled)
          Sets if the new connection about to be establish is going to be debugged.
 void setExpiredCertificatesCheckEnabled(boolean expiredCertificatesCheckEnabled)
          Sets if certificates presented by the server are going to be checked for their validity.
 void setKeystorePath(String keystorePath)
          Sets the path to the keystore file.
 void setKeystoreType(String keystoreType)
          Sets the keystore type.
 void setNotMatchingDomainCheckEnabled(boolean notMatchingDomainCheckEnabled)
          Sets if certificates presented by the server are going to be checked for their domain.
 void setPKCS11Library(String pkcs11Library)
          Sets the PKCS11 library file location, needed when the Keystore type is PKCS11
 void setReconnectionAllowed(boolean isAllowed)
          Sets if the reconnection mechanism is allowed to be used.
 void setRosterLoadedAtLogin(boolean rosterLoadedAtLogin)
          Sets if the roster will be loaded from the server when logging in.
 void setSASLAuthenticationEnabled(boolean saslAuthenticationEnabled)
          Sets whether the client will use SASL authentication when logging into the server.
 void setSecurityMode(ConnectionConfiguration.SecurityMode securityMode)
          Sets the TLS security mode used when making the connection.
 void setSelfSignedCertificateEnabled(boolean selfSignedCertificateEnabled)
          Sets if self-signed certificates are going to be accepted.
 void setSendPresence(boolean sendPresence)
          Sets if an initial available presence will be sent to the server.
 void setServiceName(String serviceName)
          Sets the server name, also known as XMPP domain of the target server.
 void setSocketFactory(javax.net.SocketFactory socketFactory)
          Sets the socket factory used to create new xmppConnection sockets.
 void setTruststorePassword(String truststorePassword)
          Sets the password to use to access the trust store file.
 void setTruststorePath(String truststorePath)
          Sets the path to the trust store file.
 void setTruststoreType(String truststoreType)
          Sets the trust store type.
 void setVerifyChainEnabled(boolean verifyChainEnabled)
          Sets if the whole chain of certificates presented by the server are going to be checked.
 void setVerifyRootCAEnabled(boolean verifyRootCAEnabled)
          Sets if root CA checking is going to be done.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proxy

protected ProxyInfo proxy
Constructor Detail

ConnectionConfiguration

public ConnectionConfiguration(String serviceName)
Creates a new ConnectionConfiguration for the specified service name. A DNS SRV lookup will be performed to find out the actual host address and port to use for the connection.

Parameters:
serviceName - the name of the service provided by an XMPP server.

ConnectionConfiguration

public ConnectionConfiguration(String serviceName,
                               ProxyInfo proxy)
Creates a new ConnectionConfiguration for the specified service name with specified proxy. A DNS SRV lookup will be performed to find out the actual host address and port to use for the connection.

Parameters:
serviceName - the name of the service provided by an XMPP server.
proxy - the proxy through which XMPP is to be connected

ConnectionConfiguration

public ConnectionConfiguration(String host,
                               int port,
                               String serviceName)
Creates a new ConnectionConfiguration using the specified host, port and service name. This is useful for manually overriding the DNS SRV lookup process that's used with the ConnectionConfiguration(String) constructor. For example, say that an XMPP server is running at localhost in an internal network on port 5222 but is configured to think that it's "example.com" for testing purposes. This constructor is necessary to connect to the server in that case since a DNS SRV lookup for example.com would not point to the local testing server.

Parameters:
host - the host where the XMPP server is running.
port - the port where the XMPP is listening.
serviceName - the name of the service provided by an XMPP server.

ConnectionConfiguration

public ConnectionConfiguration(String host,
                               int port,
                               String serviceName,
                               ProxyInfo proxy)
Creates a new ConnectionConfiguration using the specified host, port and service name. This is useful for manually overriding the DNS SRV lookup process that's used with the ConnectionConfiguration(String) constructor. For example, say that an XMPP server is running at localhost in an internal network on port 5222 but is configured to think that it's "example.com" for testing purposes. This constructor is necessary to connect to the server in that case since a DNS SRV lookup for example.com would not point to the local testing server.

Parameters:
host - the host where the XMPP server is running.
port - the port where the XMPP is listening.
serviceName - the name of the service provided by an XMPP server.
proxy - the proxy through which XMPP is to be connected

ConnectionConfiguration

public ConnectionConfiguration(String host,
                               int port)
Creates a new ConnectionConfiguration for a connection that will connect to the desired host and port.

Parameters:
host - the host where the XMPP server is running.
port - the port where the XMPP is listening.

ConnectionConfiguration

public ConnectionConfiguration(String host,
                               int port,
                               ProxyInfo proxy)
Creates a new ConnectionConfiguration for a connection that will connect to the desired host and port with desired proxy.

Parameters:
host - the host where the XMPP server is running.
port - the port where the XMPP is listening.
proxy - the proxy through which XMPP is to be connected
Method Detail

setServiceName

public void setServiceName(String serviceName)
Sets the server name, also known as XMPP domain of the target server.

Parameters:
serviceName - the XMPP domain of the target server.

getServiceName

public String getServiceName()
Returns the server name of the target server.

Returns:
the server name of the target server.

getHost

public String getHost()
Returns the host to use when establishing the connection. The host and port to use might have been resolved by a DNS lookup as specified by the XMPP spec (and therefore may not match the service name.

Returns:
the host to use when establishing the connection.

getPort

public int getPort()
Returns the port to use when establishing the connection. The host and port to use might have been resolved by a DNS lookup as specified by the XMPP spec.

Returns:
the port to use when establishing the connection.

getSecurityMode

public ConnectionConfiguration.SecurityMode getSecurityMode()
Returns the TLS security mode used when making the connection. By default, the mode is ConnectionConfiguration.SecurityMode.enabled.

Returns:
the security mode.

setSecurityMode

public void setSecurityMode(ConnectionConfiguration.SecurityMode securityMode)
Sets the TLS security mode used when making the connection. By default, the mode is ConnectionConfiguration.SecurityMode.enabled.

Parameters:
securityMode - the security mode.

getTruststorePath

public String getTruststorePath()
Retuns the path to the trust store file. The trust store file contains the root certificates of several well known CAs. By default, will attempt to use the the file located in $JREHOME/lib/security/cacerts.

Returns:
the path to the truststore file.

setTruststorePath

public void setTruststorePath(String truststorePath)
Sets the path to the trust store file. The truststore file contains the root certificates of several well?known CAs. By default Smack is going to use the file located in $JREHOME/lib/security/cacerts.

Parameters:
truststorePath - the path to the truststore file.

getTruststoreType

public String getTruststoreType()
Returns the trust store type, or null if it's not set.

Returns:
the trust store type.

setTruststoreType

public void setTruststoreType(String truststoreType)
Sets the trust store type.

Parameters:
truststoreType - the trust store type.

getTruststorePassword

public String getTruststorePassword()
Returns the password to use to access the trust store file. It is assumed that all certificates share the same password in the trust store.

Returns:
the password to use to access the truststore file.

setTruststorePassword

public void setTruststorePassword(String truststorePassword)
Sets the password to use to access the trust store file. It is assumed that all certificates share the same password in the trust store.

Parameters:
truststorePassword - the password to use to access the truststore file.

getKeystorePath

public String getKeystorePath()
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.

Returns:
the path to the keystore file.

setKeystorePath

public void setKeystorePath(String keystorePath)
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.

getKeystoreType

public String getKeystoreType()
Returns the keystore type, or null if it's not set.

Returns:
the keystore type.

setKeystoreType

public void setKeystoreType(String keystoreType)
Sets the keystore type.

Parameters:
keystoreType - the keystore type.

getPKCS11Library

public String getPKCS11Library()
Returns the PKCS11 library file location, needed when the Keystore type is PKCS11.

Returns:
the path to the PKCS11 library file

setPKCS11Library

public void setPKCS11Library(String pkcs11Library)
Sets the PKCS11 library file location, needed when the Keystore type is PKCS11

Parameters:
pkcs11Library - the path to the PKCS11 library file

isVerifyChainEnabled

public boolean isVerifyChainEnabled()
Returns true if the whole chain of certificates presented by the server are going to be checked. By default the certificate chain is not verified.

Returns:
true if the whole chaing of certificates presented by the server are going to be checked.

setVerifyChainEnabled

public void setVerifyChainEnabled(boolean verifyChainEnabled)
Sets if the whole chain of certificates presented by the server are going to be checked. By default the certificate chain is not verified.

Parameters:
verifyChainEnabled - if the whole chaing of certificates presented by the server are going to be checked.

isVerifyRootCAEnabled

public boolean isVerifyRootCAEnabled()
Returns true if root CA checking is going to be done. By default checking is disabled.

Returns:
true if root CA checking is going to be done.

setVerifyRootCAEnabled

public void setVerifyRootCAEnabled(boolean verifyRootCAEnabled)
Sets if root CA checking is going to be done. By default checking is disabled.

Parameters:
verifyRootCAEnabled - if root CA checking is going to be done.

isSelfSignedCertificateEnabled

public boolean isSelfSignedCertificateEnabled()
Returns true if self-signed certificates are going to be accepted. By default this option is disabled.

Returns:
true if self-signed certificates are going to be accepted.

setSelfSignedCertificateEnabled

public void setSelfSignedCertificateEnabled(boolean selfSignedCertificateEnabled)
Sets if self-signed certificates are going to be accepted. By default this option is disabled.

Parameters:
selfSignedCertificateEnabled - if self-signed certificates are going to be accepted.

isExpiredCertificatesCheckEnabled

public boolean isExpiredCertificatesCheckEnabled()
Returns true if certificates presented by the server are going to be checked for their validity. By default certificates are not verified.

Returns:
true if certificates presented by the server are going to be checked for their validity.

setExpiredCertificatesCheckEnabled

public void setExpiredCertificatesCheckEnabled(boolean expiredCertificatesCheckEnabled)
Sets if certificates presented by the server are going to be checked for their validity. By default certificates are not verified.

Parameters:
expiredCertificatesCheckEnabled - if certificates presented by the server are going to be checked for their validity.

isNotMatchingDomainCheckEnabled

public boolean isNotMatchingDomainCheckEnabled()
Returns true if certificates presented by the server are going to be checked for their domain. By default certificates are not verified.

Returns:
true if certificates presented by the server are going to be checked for their domain.

setNotMatchingDomainCheckEnabled

public void setNotMatchingDomainCheckEnabled(boolean notMatchingDomainCheckEnabled)
Sets if certificates presented by the server are going to be checked for their domain. By default certificates are not verified.

Parameters:
notMatchingDomainCheckEnabled - if certificates presented by the server are going to be checked for their domain.

isCompressionEnabled

public boolean isCompressionEnabled()
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.

Returns:
true if the connection is going to use stream compression.

setCompressionEnabled

public void setCompressionEnabled(boolean compressionEnabled)
Sets 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.

Parameters:
compressionEnabled - if the connection is going to use stream compression.

isSASLAuthenticationEnabled

public boolean isSASLAuthenticationEnabled()
Returns true if the client is going to use SASL authentication when logging into the server. If SASL authenticatin fails then the client will try to use non-sasl authentication. By default SASL is enabled.

Returns:
true if the client is going to use SASL authentication when logging into the server.

setSASLAuthenticationEnabled

public void setSASLAuthenticationEnabled(boolean saslAuthenticationEnabled)
Sets whether the client will use SASL authentication when logging into the server. If SASL authenticatin fails then the client will try to use non-sasl authentication. By default, SASL is enabled.

Parameters:
saslAuthenticationEnabled - if the client is going to use SASL authentication when logging into the server.

isDebuggerEnabled

public boolean isDebuggerEnabled()
Returns true if the new connection about to be establish is going to be debugged. By default the value of Connection.DEBUG_ENABLED is used.

Returns:
true if the new connection about to be establish is going to be debugged.

setDebuggerEnabled

public void setDebuggerEnabled(boolean debuggerEnabled)
Sets if the new connection about to be establish is going to be debugged. By default the value of Connection.DEBUG_ENABLED is used.

Parameters:
debuggerEnabled - if the new connection about to be establish is going to be debugged.

setReconnectionAllowed

public void setReconnectionAllowed(boolean isAllowed)
Sets if the reconnection mechanism is allowed to be used. By default reconnection is allowed.

Parameters:
isAllowed - if the reconnection mechanism is allowed to use.

isReconnectionAllowed

public boolean isReconnectionAllowed()
Returns if the reconnection mechanism is allowed to be used. By default reconnection is allowed.

Returns:
if the reconnection mechanism is allowed to be used.

setSocketFactory

public void 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.

setSendPresence

public void 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 a false value.

Parameters:
sendPresence - true if an initial available presence will be sent while logging in.

isRosterLoadedAtLogin

public boolean isRosterLoadedAtLogin()
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.

Returns:
true if the roster will be loaded from the server when logging in.

setRosterLoadedAtLogin

public void setRosterLoadedAtLogin(boolean rosterLoadedAtLogin)
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.

Parameters:
rosterLoadedAtLogin - if the roster will be loaded from the server when logging in.

getCallbackHandler

public javax.security.auth.callback.CallbackHandler getCallbackHandler()
Returns 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.

Returns:
a CallbackHandler to obtain information, such as the password or principal information during the SASL authentication.

setCallbackHandler

public void setCallbackHandler(javax.security.auth.callback.CallbackHandler callbackHandler)
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.

getSocketFactory

public javax.net.SocketFactory getSocketFactory()
Returns the socket factory used to create new xmppConnection sockets. This is useful when connecting through SOCKS5 proxies.

Returns:
socketFactory used to create new sockets.

Smack

Copyright © 2003-2007 Jive Software.