LDAP: Multiple Provider URLs

The LDAP service provider uses this URL to configure its connection to the directory server. Only the host, port, and dn parts of the URL are relevant in this setting. Supplying other parts of the URL results in a ConfigurationException(in the API reference documentation). Most commonly we use just one URL. But we can also supply a space-separated list of URLs. In this case, the LDAP provider will attempt to use each URL in turn until it is able to create a successful connection. How to determine, on which server, are we connected to?? The LDAP provider set Context.PROVIDER_URL property to the successful URL, so that the application can determine which URL is being used. Here is an example of how to specify a list of URLs.

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”);

// Specify list of space-separated URLs
env.put(Context.PROVIDER_URL, “ldap://host1:389/o=JNDITutorial ” + “ldap://host2:389/o=JNDITutorial ” + “ldap://host3:389/o=JNDITutorial ” + “ldap://host4:389/o=JNDITutorial”);

// Create initial
context DirContext ctx = new InitialDirContext(env);

// See which server was used
System.out.println(ctx.getEnvironment().get(Context.PROVIDER_URL));

For more info: http://docs.oracle.com/javase/jndi/tutorial/ldap/misc/url.html

Advertisements
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: