• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

LDAP: error

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sumon Mukherjee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic