Package org.ldaptive

Class DnsSrvConnectionStrategy

  • All Implemented Interfaces:
    ConnectionStrategy

    public class DnsSrvConnectionStrategy
    extends Object
    implements ConnectionStrategy
    DNS SRV connection strategy. Queries a DNS server for SRV records and uses those records to construct a list of URLs. A time to live can be set to control how often the DNS server is consulted. See http://www.ietf.org/rfc/rfc2782.txt.
    • Field Detail

      • DEFAULT_TTL

        private static final long DEFAULT_TTL
        Default time to live for DNS results. Value is 3600000L.
        See Also:
        Constant Field Values
      • logger

        protected final Logger logger
        Logger for this class.
      • srvTtl

        private long srvTtl
        Time to live for SRV records in milliseconds.
    • Constructor Detail

      • DnsSrvConnectionStrategy

        public DnsSrvConnectionStrategy()
        Creates a new DNS SRV connection strategy.
      • DnsSrvConnectionStrategy

        public DnsSrvConnectionStrategy​(long ttl)
        Creates a new DNS SRV connection strategy.
        Parameters:
        ttl - time to live in milliseconds for SRV records
      • DnsSrvConnectionStrategy

        public DnsSrvConnectionStrategy​(Map<String,​Object> env,
                                        long ttl)
        Creates a new DNS SRV connection strategy.
        Parameters:
        env - JNDI environment
        ttl - time to live in milliseconds for SRV records
    • Method Detail

      • getJndiEnvironment

        public Map<String,​Object> getJndiEnvironment()
        Returns the JNDI environment used for DNS lookup.
        Returns:
        jndi environment
      • getTimeToLive

        public long getTimeToLive()
        Returns the time that DNS lookups will be cached.
        Returns:
        time to live in milliseconds
      • setTimeToLive

        public void setTimeToLive​(long ttl)
        Sets the time that DNS lookups will be cached.
        Parameters:
        ttl - time to live in milliseconds
      • getLdapUrls

        public String[] getLdapUrls​(ConnectionFactoryMetadata metadata)
        Returns a list of URLs retrieved from DNS SRV records. The LDAP URL in the supplied metadata can be a space delimited list of DNS servers, each will be tried in order.
        Specified by:
        getLdapUrls in interface ConnectionStrategy
        Parameters:
        metadata - which can be used to produce the URL list
        Returns:
        list of URLs to attempt connections to
      • retrieveDNSRecords

        protected List<DnsSrvConnectionStrategy.SrvRecord> retrieveDNSRecords​(String name,
                                                                              Map<String,​Object> props,
                                                                              long ttl)
                                                                       throws NamingException
        Uses JNDI to retrieve the DNS SRV record from the supplied url. The supplied properties are passed into the JNDI context.
        Parameters:
        name - of the SRV records
        props - for the JNDI context
        ttl - time to live for each SRV record
        Returns:
        list of LDAP URLs
        Throws:
        NamingException - if the DNS record cannot be retrieved
      • sortSrvRecords

        protected List<DnsSrvConnectionStrategy.SrvRecord> sortSrvRecords​(List<DnsSrvConnectionStrategy.SrvRecord> records)
        Sorts the supplied SRV records according to RFC 2782. Records with the lowest priority are first. Records with the same priority are arranged by weight with higher weights having a greater chance to be ordered first.
        Parameters:
        records - to sort
        Returns:
        sorted records