aspose file tools*
The moose likes Java in General and the fly likes LDAPReferralException -  how to reterive multiple referrals returned by the server. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "LDAPReferralException -  how to reterive multiple referrals returned by the server." Watch "LDAPReferralException -  how to reterive multiple referrals returned by the server." New topic
Author

LDAPReferralException - how to reterive multiple referrals returned by the server.

java Prentice
Greenhorn

Joined: Nov 28, 2012
Posts: 1
Hi All,

On OpenLDAP Server setup we have done referral setting for ldapsrv2 and ldapsrv3 on ldapsrv1

Following are the scenarios that were examine using ldap client (on ldapsrv2) for connection to ldapsrv1 (192.168.146.10):
Scenario-1:
---------------
1. Using ‘ldapsearch’ command searched the users on ldapsrv1 with search baseDN: dc=nhst,dc=com 2. Returned the user info and returned referral to ldapsrv2 as search type is sub-tree search i.e.
Ref: ldap://ldapsrv2/dc=child,dc=nhst,dc=com??sub
Scenario-2:
---------------
1. Using ‘ldapsearch’ command searched the users on ldapsrv2 with search baseDN: dc=nhst,dc=com 2. Returned no user info but returned referral to ldapsrv2 as search type is sub-tree search and also referral to ldapsrv3 as this ref is added under dummy sub-tree entry dc=child2,dc=hcl,dc=com i.e.
Ref: ldap://ldapsrv2/dc=child,dc=nhst,dc=com??sub
Ref: ldap://ldapsrv3/dc=nec,dc=com??sub

Issue :

I want to build same client in java for authentication openldap users using LdapContextFactory, but when i set the context.referral as throw. it only return one referral

catch (LdapReferralException e) {
String url = e.getReferralInfo().toString();
boolean moreRefferals = true;
while (moreRefferals) {
try {
//getcred(env);
String[] urls = url.split("/ou=people,");
String provider_url = urls[0];
String searc_base = urls[1].replace("??sub", "").trim();
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager," + searc_base);
env.put(Context.PROVIDER_URL, provider_url);
try {
ctx = new InitialDirContext(env);
final NamingEnumeration<SearchResult> answer = ctx
.search(searc_base, searchFilter,
searchCtls);
while (answer.hasMore()) {
answer.next();
System.out.println("success");
moreRefferals = false;
}
} catch (LdapReferralException e1) {
url = e.getReferralInfo().toString();
e.retryReferral();
}
} catch (AuthenticationException ne) {
System.out.println("Authentication failed: " + e);

return false;

} catch (NamingException ne) {
e.skipReferral();
System.out.println("Referral failed: " + ne);
}
}
even if i use e.retryReferral().

Please suggest me any other way by which i can get referrals returned by the server.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: LDAPReferralException - how to reterive multiple referrals returned by the server.