Class SniAwareLdapSocketFactory

java.lang.Object
javax.net.SocketFactory
javax.net.ssl.SSLSocketFactory
org.exoplatform.services.organization.idm.ldap.SniAwareLdapSocketFactory
All Implemented Interfaces:
Comparator<SniAwareLdapSocketFactory>

public class SniAwareLdapSocketFactory extends SSLSocketFactory implements Comparator<SniAwareLdapSocketFactory>
SSL socket factory for ldaps:// connections whose host name (e.g. a CNAME, or a name backed by round-robin DNS) resolves to more than one server address.

The JDK's default socket handling only ever connects to a single address for a host name and never retries other addresses behind the same name if that first attempt fails. This factory instead enumerates every address behind the configured host name (via InetAddress.getAllByName(java.lang.String)) and tries each in turn, while still performing the TLS handshake - SNI and certificate hostname verification - against the original host name rather than the numeric address actually connected to.

This distinction matters: verifying against a raw IP address instead of the configured host name would silently defeat hostname verification (most server certificates are not issued for IP addresses), which is why the original host name is always passed through to the delegate factory's SSLSocketFactory.createSocket(Socket, String, int, boolean).

Enabled by setting exo.ldap.sni.enabled=true; the connect timeout (ms) used for each candidate address can be tuned with exo.ldap.sni.connect.timeout. When unset, it falls back to whatever com.sun.jndi.ldap.connect.timeout value is already configured - either as a customJNDIConnectionParameters entry (the way this timeout is shipped by default) or as a JVM system property - so switching SNI on does not silently replace a timeout the admin already set, and finally defaults to 10000 if neither is present. See connectTimeoutMs() for the exact precedence.

Registered via the standard JNDI LDAP java.naming.ldap.factory.socket connection property, whose contract requires a public static getDefault() method (mirroring SSLSocketFactory.getDefault()) - the JNDI LDAP provider obtains the factory instance by reflectively invoking that method, not the class constructor.

Implements Comparator (comparing purely on class identity) because com.sun.jndi.ldap.LdapPoolManager only allows pooling LDAP connections that use a custom socket factory when that factory's class implements java.util.Comparator - without it, enabling this feature would silently disable com.sun.jndi.ldap.connect.pool.

  • Field Details

  • Constructor Details

    • SniAwareLdapSocketFactory

      protected SniAwareLdapSocketFactory()
  • Method Details