LDAP NamingException while getting attributes

S

Sharif Islam

javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr:
DSID-031006CC, problem 5012 (DIR_ERROR), data 0


I am able to bind fine with my active directory server, but when I try
to get any attributeu, I get the above error. I need to get the
givenName and sn. I think I am proving the wrong context?


CODE:
String ldap_search_context ="OU=users,DC=mycompany,DC=com";
String attlist[] = {"sn"}
try
{
DirContext ctx = new InitialDirContext(env);
NamingEnumeration answer = null;
System.out.println("Connection toString: " + ctx.toString());
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute("cn","username"));
System.out.println(matchAttrs.toString());
answer = ctx.search(ldap_search_context, matchAttrs,attlist);
while(answer.hasMore())
{
SearchResult sr = (SearchResult)answer.next();
System.out.println(">>>" + sr.getName());

}

}
 
R

Roedy Green

DirContext ctx = new InitialDirContext(env);

You don't show your definition of env. Here is the sort of thing you
need:


Hashtable<String, String> env = new Hashtable<String, String>();
env.put( "java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory" );
DirContext ictx = new InitialDirContext( env );
 
N

Nigel Wade

Sharif said:
javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr:
DSID-031006CC, problem 5012 (DIR_ERROR), data 0


I am able to bind fine with my active directory server, but when I try
to get any attributeu, I get the above error. I need to get the
givenName and sn. I think I am proving the wrong context?


CODE:
String ldap_search_context ="OU=users,DC=mycompany,DC=com";
String attlist[] = {"sn"}
try
{
DirContext ctx = new InitialDirContext(env);
NamingEnumeration answer = null;
System.out.println("Connection toString: " + ctx.toString());
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute("cn","username"));

The BasicAttribute you want to match needs to be a valid directory search
string.

E.g.
new BasicAttribute("(cn=username)")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top