Using ActiveDirectoryDnsLocator

This user guide is comprised of two examples of the ActiveDirectoryDnsLocator.

Contents:

Basic Example

In few lines you have a usable ActiveDirectoryDnsLocator:

import net.sf.michaelo.activedirectory.ActiveDirectoryDnsLocator;
import javax.naming.directory.DirContext;
[…]
ActiveDirectoryDnsLocator.Builder builder = new ActiveDirectoryDnsLocator.Builder();
ActiveDirectoryDnsLocator locator = builder.build();
// try and catch block omitted for the sake of brevity,
// handle NamingException appropriately
HostPort[] hostPorts = locator.locate("ldap", "ad.example.com");
[…]

Advanced Example

A more complex example includes several configuration options as described in the builder's Javadoc:

import net.sf.michaelo.activedirectory.ActiveDirectoryDnsLocator;
import javax.naming.directory.DirContext;
ActiveDirectoryDnsLocator.Builder builder = new ActiveDirectoryDnsLocator.Builder();
// Make it fail fast
builder.additionalProperty("com.sun.jndi.dns.timeout.initial", "200")
       .additionalProperty("com.sun.jndi.dns.timeout.retries", "2");

ActiveDirectoryDnsLocator locator = builder.build();
// try and catch block omitted for the sake of brevity,
// handle NamingException appropriately
HostPort[] hostPorts = locator.locate("kerberos", "debln-01", "ad.example.com");
[…]