Package org.ldaptive
Class DnsSrvConnectionStrategy
- java.lang.Object
-
- org.ldaptive.AbstractConnectionStrategy
-
- org.ldaptive.DnsSrvConnectionStrategy
-
- All Implemented Interfaces:
java.lang.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.- Author:
- Middleware Services
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.ldaptive.AbstractConnectionStrategy
AbstractConnectionStrategy.DefaultLdapURLIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.time.Duration
DEFAULT_TTL
Default time to live for DNS results.-
Fields inherited from class org.ldaptive.AbstractConnectionStrategy
ldapURLSet, logger
-
-
Constructor Summary
Constructors Constructor Description DnsSrvConnectionStrategy()
Default constructor.DnsSrvConnectionStrategy(java.time.Duration ttl)
Creates a new DNS SRV connection strategy.DnsSrvConnectionStrategy(DNSContextFactory factory)
Creates a new DNS SRV connection strategy.DnsSrvConnectionStrategy(DNSContextFactory factory, java.time.Duration ttl)
Creates a new DNS SRV connection strategy.DnsSrvConnectionStrategy(DNSContextFactory factory, java.time.Duration ttl, boolean ssl)
Creates a new DNS SRV connection strategy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<LdapURL>
iterator()
Returns a list of URLs retrieved from DNS SRV records.DnsSrvConnectionStrategy
newInstance()
Create a deep copy of this strategy.protected java.lang.String[]
parseDnsUrl(java.lang.String url)
Parses a DNS URL of the form dns://hostname/domain?record.protected java.lang.String[]
parseUrl(java.lang.String url)
Parses the supplied URL.void
populate(java.lang.String urls, LdapURLSet urlSet)
Populates aLdapURLSet
from the URL string provided at configuration time.protected java.util.Set<SRVRecord>
readSrvRecords(java.lang.String urls)
Parses the supplied DNS URL string and reads SRV records from DNS.protected java.util.Set<SRVRecord>
retrieveDNSRecords()
InvokeDNSResolver.resolve(String)
for each resolver until results are found.-
Methods inherited from class org.ldaptive.AbstractConnectionStrategy
failure, getActivateCondition, getRetryCondition, initialize, isInitialized, setRetryCondition, success, toString
-
-
-
-
Constructor Detail
-
DnsSrvConnectionStrategy
public DnsSrvConnectionStrategy()
Default constructor.
-
DnsSrvConnectionStrategy
public DnsSrvConnectionStrategy(java.time.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, java.time.Duration ttl)
Creates a new DNS SRV connection strategy.- Parameters:
factory
- DNS context factoryttl
- time to live for SRV records
-
DnsSrvConnectionStrategy
public DnsSrvConnectionStrategy(DNSContextFactory factory, java.time.Duration ttl, boolean ssl)
Creates a new DNS SRV connection strategy.- Parameters:
factory
- DNS context factoryttl
- time to live for SRV recordsssl
- whether SRV records should produce LDAPS URLs
-
-
Method Detail
-
populate
public void populate(java.lang.String urls, LdapURLSet urlSet)
Description copied from interface:ConnectionStrategy
Populates aLdapURLSet
from the URL string provided at configuration time.- Specified by:
populate
in interfaceConnectionStrategy
- Overrides:
populate
in classAbstractConnectionStrategy
- Parameters:
urls
- Space-delimited string of URLs describing the LDAP hosts to connect to. The URLs in the string are commonlyldap://
orldaps://
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 forDnsSrvConnectionStrategy
that use URLs with the schemedns:
.urlSet
- LDAP URL set to populate.
-
readSrvRecords
protected java.util.Set<SRVRecord> readSrvRecords(java.lang.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 java.lang.String[] parseUrl(java.lang.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 java.lang.String[] parseDnsUrl(java.lang.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 java.util.Iterator<LdapURL> iterator()
Returns a list of URLs retrieved from DNS SRV records.- Returns:
- list of URLs to attempt connections to
-
retrieveDNSRecords
protected java.util.Set<SRVRecord> retrieveDNSRecords()
InvokeDNSResolver.resolve(String)
for each resolver until results are found.- Returns:
- list of LDAP URLs
-
newInstance
public DnsSrvConnectionStrategy newInstance()
Description copied from interface:ConnectionStrategy
Create a deep copy of this strategy.- Returns:
- new instance of this connection strategy
-
-