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.
 
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, String serviceName)
          Creates a new ConnectionConfiguration using the specified host, port and service name.
 
Method Summary
 String getHost()
          Returns the host to use when establishing the connection.
 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 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 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 setNotMatchingDomainCheckEnabled(boolean notMatchingDomainCheckEnabled)
          Sets if certificates presented by the server are going to be checked for their domain.
 void setReconnectionAllowed(boolean isAllowed)
          Sets if the reconnection mechanism is allowed to be used.
 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 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
 

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 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)
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.
Method Detail

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.

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 XMPPConnection.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 XMPPConnection.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.

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.