Package org.ldaptive

Class DnsSrvConnectionStrategy

  • All Implemented Interfaces:
    Iterable<LdapURL>, ConnectionStrategy

    public class DnsSrvConnectionStrategy
    extends AbstractConnectionStrategy
    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

        protected static final Duration DEFAULT_TTL
        Default time to live for DNS results.
      • dnsContextFactory

        private final DNSContextFactory dnsContextFactory
        DNS context factory to override initialization parameters.
      • srvTtl

        private final Duration srvTtl
        Time to live for SRV records.
      • useSSL

        private final boolean useSSL
        Connect to LDAP using LDAPS.
      • ldapUrls

        private String ldapUrls
        LDAP URL string used to initialize this strategy.
      • expirationTime

        private Instant expirationTime
        SRV records expiration time.
    • Constructor Detail

      • DnsSrvConnectionStrategy

        public DnsSrvConnectionStrategy()
        Default constructor.
      • DnsSrvConnectionStrategy

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

        public DnsSrvConnectionStrategy​(DNSContextFactory factory)
        Creates a new DNS SRV connection strategy.
        Parameters:
        factory - DNS context factory
      • DnsSrvConnectionStrategy

        public DnsSrvConnectionStrategy​(DNSContextFactory factory,
                                        Duration ttl)
        Creates a new DNS SRV connection strategy.
        Parameters:
        factory - DNS context factory
        ttl - time to live for SRV records
      • DnsSrvConnectionStrategy

        public DnsSrvConnectionStrategy​(DNSContextFactory factory,
                                        Duration ttl,
                                        boolean ssl)
        Creates a new DNS SRV connection strategy.
        Parameters:
        factory - DNS context factory
        ttl - time to live for SRV records
        ssl - whether SRV records should produce LDAPS URLs
    • Method Detail

      • populate

        public void populate​(String urls,
                             LdapURLSet urlSet)
        Description copied from interface: ConnectionStrategy
        Populates a LdapURLSet from the URL string provided at configuration time.
        Specified by:
        populate in interface ConnectionStrategy
        Overrides:
        populate in class AbstractConnectionStrategy
        Parameters:
        urls - Space-delimited string of URLs describing the LDAP hosts to connect to. The URLs in the string are commonly ldap:// or ldaps:// URLs that directly describe the hosts to connect to, but may also describe a resource from which to obtain LDAP connection URLs as is the case for DnsSrvConnectionStrategy that use URLs with the scheme dns:.
        urlSet - LDAP URL set to populate.
      • readSrvRecords

        protected Set<SRVRecord> readSrvRecords​(String urls)
        Parses the supplied DNS URL string and reads SRV records from DNS.
        Parameters:
        urls - to parse
        Returns:
        Set of DNS SRV records ordered first by priority and then by weight.
      • parseUrl

        protected String[] parseUrl​(String url)
        Parses the supplied URL. If the URL has an ldap scheme, it is inspected for a baseDN which will be used as the domain. Otherwise, the URL is assumed to have a dns scheme.
        Parameters:
        url - to parse
        Returns:
        array containing the DNS URL and the record name in that order
      • parseDnsUrl

        protected String[] parseDnsUrl​(String url)
        Parses a DNS URL of the form dns://hostname/domain?record. Where record is the DNS record to retrieve.
        Parameters:
        url - to parse
        Returns:
        array containing the DNS URL and the record name in that order
      • iterator

        public Iterator<LdapURL> iterator()
        Returns a list of URLs retrieved from DNS SRV records.
        Returns:
        list of URLs to attempt connections to