wood burning stoves 2.0*
The moose likes Java in General and the fly likes LDAP: error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "LDAP: error " Watch "LDAP: error " New topic
Author

LDAP: error

Sumon Mukherjee
Greenhorn

Joined: Dec 19, 2007
Posts: 12
Hi
I am using the following LDAP query to retrieve data from the Active Directory environment:
< LDAP://kworld.myserver.com:123/dc=uk,dc=kworld,dc=myserver,dc=com>;(&(ObjectCategory=person)(ObjectClass=user)(employeeID=*)(!(userAccountControl=514)));UserPrincipalName,CreateTimeStamp,GivenName,TelephoneNumber,HomePhone,Name,sn,Company,c,l,st,StreetAddress,distinguishedname;subtree

I am getting the error -
LDAP: error code 1 - 00000000: LdapErr: DSID-0C090627- Get Active Directory RootDSE with JNDI

//-----------------------------------------------------------------------------------------//
// My Java code for the above is :
//-----------------------------------------------------------------------------------------//

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

public class KPMGADSearch{

public static void main(String args[]) throws Exception{
dc.controlArrtibutesInResults();
}

/**
* This methos shows how to search and control arrtibutes returned in the result.
* Create search controls and allow java objects to be returned in the results.
*/
public void controlArrtibutesInResults() throws Exception{
DirContext ctx= getDirContext();

// Specify the ids of the attributes to return
String[] attrIDs = {"CreateTimeStamp" , "ModifyTimeStamp" , "GivenName" , "TelephoneNumber" , "HomePhone" , "Name" , "sn" , "Company" , "Title" ,"Mobile" , "c" , "l" , "st" , "Mail" , "EmployeeID" , "PostalCode" , "distinguishedname"};
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes (attrIDs);
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = "(&(ObjectCategory=person)(ObjectClass=user)(employeeID=*)(!(userAccountControl=514)))";
String base = "dc=uk,dc=kworld,dc=kpmg,dc=com";
NamingEnumeration answer = ctx.search(base, filter, ctls);
formatResults(answer);
ctx.close();
}

/*
* Generic method to format the NamingEnumeration returned from a search.
*/
public void formatResults(NamingEnumeration enumeration) throws Exception{
int count=0;
try {
while (enumeration.hasMore ()) {
SearchResult sr = (SearchResult)enumeration.next();
System.out.println("SEARCH RESULT:" + sr.getName());
formatAttributes(sr.getAttributes());
System.out.println("====================================================");
count++;
}

System.out.println("Search returned "+ count+ " results");
} catch (NamingException e) {
e.printStackTrace();
}
}

/*
* Generic method to format the Attributes .Displays all the multiple values of
* each Attribute in the Attributes
*/
public void formatAttributes(Attributes attrs) throws Exception{
if (attrs == null) {
System.out.println("This result has no attributes");
} else {
try {
for (NamingEnumeration enumeration = attrs.getAll(); enumeration.hasMore() {
Attribute attrib = (Attribute)enumeration.next();
System.out.println("ATTRIBUTE :" + attrib.getID());
for (NamingEnumeration e = attrib.getAll();e.hasMore()
System.out.println("\t\t = " + e.next());
}
} catch (NamingException e) {
e.printStackTrace();
}
}
}

/** Generic method to obtain a reference to a DirContext */
public DirContext getDirContext() throws Exception{
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory ");
env.put(Context.PROVIDER_URL, "LDAP://kworld.myserver.com:123");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
return ctx;
}
}
//-----------------------------------------------------------------------------------------//

I am getting the following error :
javax.naming.NamingException: [LDAP: error code 1 - 00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece remaining name 'dc=uk,dc=kworld,dc=myserver,dc=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3028)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2934)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2740)
at com.sun.jndi.ldap.LdapCtx.searchAux (LdapCtx.java:1811)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1734)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:368)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search (PartialCompositeDirContext.java:328)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:313)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:238)
at com.hp.kpmg.ldap.KPMGADSearch.controlArrtibutesInResults(KPMGADSearch.java:118)
at com.hp.kpmg.ldap.KPMGADSearch.main(KPMGADSearch.java:44)
Exception in thread "main"

Can i get some help on this ,
No clue .

thanks in advance,

Sumon
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

You can not do a search without authentication. You should add an Admin or other user name and password to the properties of the initial dir context.

This turorial will give you necessary information.


apigee, a better way to API!
Sumon Mukherjee
Greenhorn

Joined: Dec 19, 2007
Posts: 12
Thanks for the reply,

As you can see there is no authentification required so i added the following piece of code :
env.put(Context.SECURITY_AUTHENTICATION,"none");
still i get the same problem.

I am totally stuck .

If you can see my ldap query :
<LDAP://kworld.myserver.com:123/dc=uk,dc=kworld,dc=myserver,dc=com>


So for this have set these values correctly :
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "LDAP://kworld.myserver.com:123");
DirContext ctx = new InitialDirContext(env);
String base = "dc=uk,dc=kworld,dc=kpmg,dc=com";

and i am searching as
NamingEnumeration answer = ctx.search(base, filter, ctls)

I dont see any authentification to be required here.

regards,
Sumon
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by Sumon Mukherjee:

As you can see there is no authentification required so i added the following piece of code :
env.put(Context.SECURITY_AUTHENTICATION,"none");


Why do you say so? The ldap server you are connecting to may not allow an anonymous bind (atleast the error message suggests that). While searching also admin or other user's password is required.
 
 
subject: LDAP: error
 
Similar Threads
LDAP Search
[LDAP: error code 32 - No Such Object]; remaining name ''
LDAP and NamingEnumeration
cannot connect to LDAP through JNDI
LDAP: error code 53 - Function Not Implemented