Following LDAP Referrals in Java

As with PHP, to follow referrals in Java, you have to explicitly tell Java that you want the LDAP server to return the referral to you. In Java, the default is for the Java LDAP library to tell the LDAP server not to follow referrals. Below is an example of how to have Java tell the LDAP server that referrals should be returned:

// Set the referral property to "follow" referrals automatically
env.put(Context.REFERRAL, "follow");
// Create the initial context
DirContext ctx = new InitialDirContext(env);

Please see the following references for more information: Referrals in the JNDI and Automatically Following Referrals.