Multiple LDAP servers
We can supply a space-separated list of URLs of the LDAP server.
In this case, the LDAP provider will attempt to use each URL in turn until it is able to create a successful connection.
The LDAP provider will then set the 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 of LDAP servers.
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
// Specify list of space-separated URLs
env.put(Context.PROVIDER_URL,
"ldap://notthere:389 " +
"ldap://localhost:389 " +
"ldap://remotehost:389 " +
"ldap://thirdhost:389"); // here 389 is the LDAP default port no.
// Create initial context
DirContext ctx = new InitialDirContext(env);
// See which server was used
System.out.println(ctx.getEnvironment().get(Context.PROVIDER_URL));
// do something useful with ctx
Comments
Post a Comment