• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

AD LDAP Authentication & Data Fetch Error.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am just bouncing my head from past 2-3 days to resolve AD-LDAP related issue. In Win2000 & Exchange2000 setup, I am running my code either it is running with out giving any results [data] or throwing exception. Plz view the code & provide clue/code. Thanx a lot in advance.

Vivek Singh [viveklib@yahoo.com]

package rmi;

import java.util.Hashtable;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.naming.directory.*;

public class member{
public static void main (String[] args){

Hashtable env = new Hashtable();
String adminName = "Ex2kuser";
String adminPassword = "pawrd";
String ldapURL = "ldap://wcaxte05.catelogi-mes.catelogi.com:389";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
//set security credentials, note using simple cleartext authentication
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);

//connect to my domain controller
env.put(Context.PROVIDER_URL,ldapURL);

try {

//Create the initial directory context
LdapContext ctx = new InitialLdapContext(env,null);

//Create the search controls
SearchControls searchCtls = new SearchControls();

//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);

//specify the LDAP search filter
String searchFilter = "(&(objectClass=group)(CN=*))";

//Specify the Base for the search
String searchBase = "DC=catelogi-mes,DC=com";

//initialize counter to total the group members
int totalResults = 0;

//Specify the attributes to return
String returnedAtts[]={"member"};
searchCtls.setReturningAttributes(returnedAtts);

//Search for objects using the filter
NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);

//Loop through the search results
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();

System.out.println(">>>" + sr.getName());

//Print out the members

Attributes attrs = sr.getAttributes();
if (attrs != null) {

try {
for (NamingEnumeration ae = attrs.getAll();ae.hasMore() {
Attribute attr = (Attribute)ae.next();
System.out.println("Attribute: " + attr.getID());
for (NamingEnumeration e = attr.getAll();e.hasMore();totalResults++) {

System.out.println(" " + totalResults + ". " + e.next());
}

}

}
catch (NamingException e){
System.err.println("Problem listing members: " + e);
}

}
}

System.out.println("Total members: " + totalResults);
ctx.close();

}

catch (NamingException e) {
e.printStackTrace();
System.err.println("Problem searching directory: " + e);
}
}
}

====>> This code is running fine but not giving/fetching any results and when i m replacing line

String searchBase = "DC=catelogi-mes,DC=com";
====>>String searchBase = "DC=catelogi-mes,DC=com/";

Then it is showing exception like

javax.naming.PartialResultException: [LDAP: error code 10 - 0000202B: RefErr: DS
ID-031006D9, data 0, 1 access points
ref 1: 'catelogi-mes.com'
]; remaining name 'DC=catelogi-mes,DC=com/'
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2699)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2616)
at com.sun.jndi.ldap.LdapCtx.c_lookup(LdapCtx.java:931)
at com.sun.jndi.toolkit.ctx.ComponentContext.c_processJunction_nns(Compo
nentContext.java:322)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.c_search_nns(ComponentDi
rContext.java:171)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirCon
text.java:364)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCom
positeDirContext.java:328)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCom
positeDirContext.java:313)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.jav
a:238)
at rmi.member.main(member.java:52)
Problem searching directory: javax.naming.PartialResultException: [LDAP: error c
ode 10 - 0000202B: RefErr: DSID-031006D9, data 0, 1 access points
ref 1: 'catelogi-mes.com'
]; remaining name 'DC=catelogi-mes,DC=com/'
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic