![]() ![]() ![]() ![]() |
Referrals |
If you set the Context.REFERRAL("java.naming.referral") environment property to "follow", then referrals are followed automatically. Here's an example:
If you run this example, it produces the following results:// Set referral property to "follow" referrals automatically env.put(Context.REFERRAL, "follow"); // Create initial context DirContext ctx = new InitialDirContext(env); // Set controls for performing subtree search SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); // Perform search NamingEnumeration answer = ctx.search("", "(objectclass=*)", ctls);The example followed three referrals: "ou=People", "ou=People, ou=All", and "ou=NewHires, ou=All".>>> >>>ou=All >>>"ldap://localhost:389/ou=People, o=JNDITutorial" >>>"ldap://localhost:389/cn=Ted Geisel, ou=People, o=JNDITutorial" >>>"ldap://localhost:389/cn=Jon Ruiz, ou=People, o=JNDITutorial" ... >>>"ldap://localhost:389/ou=People, o=JNDITutorial" >>>"ldap://localhost:389/cn=Ted Geisel, ou=People, o=JNDITutorial" >>>"ldap://localhost:389/cn=Jon Ruiz, ou=People, o=JNDITutorial" ... >>>"ldap://localhost:389/ou=NewHires,o=JNDITutorial" >>>"ldap://localhost:389/cn=S. User,ou=NewHires,o=JNDITutorial" >>>"ldap://localhost:389/cn=C. User,ou=NewHires,o=JNDITutorial"Notice the names of the referred entries. They are URLs instead of names that are relative to the context being searched. If you examine the SearchResult
object for each of these referred entries and invoke the isRelative()
method on them, the method will return false. This indicates that the name is not relative and that it should be resolved relative to the initial context.
![]() ![]() ![]() ![]() |
Referrals |