Forums Register Login

LDAP: error

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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.
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 9971 times.
Similar Threads
LDAP and NamingEnumeration
[LDAP: error code 32 - No Such Object]; remaining name ''
LDAP Search
cannot connect to LDAP through JNDI
LDAP: error code 53 - Function Not Implemented
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:29:28.