go to  ForumEasy.com   
LdapPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  javax.naming.InvalidNameException
 
Subject: javax.naming.InvalidNameException
Author: JNDI
In response to: JNDI Backslash Problem: Part II -- DirContext.search()
Posted on: 05/18/2007 09:37:41 PM

While passing the exact dn "cn=temp\\\\tester,cn=users,dc=mydomain,dc=com" (the extra two backslashes are due to Java String presentation) into DirConext method search() and running the above code against AD failed and brought back error messages:


javax.naming.InvalidNameException: cn=temp\tester,cn=users,dc=mydomain,dc=com:
[LDAP: error code 34 - 0000208F: LdapErr: DSID-0C090654, comment: Error processing name, data 0, vece
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2593)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2411)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1586)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1509)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:371)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:331)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:316)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:241)



It seemed that DirContext.search() had eaten one backslash (\) internally.


 

> On 05/18/2007 09:22:32 PM JNDI wrote:


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

/**
 * Backslash.java
 * 
 * -- A sample code to demonstrate JNDI backslash (\) problem.
 * 
 * In LDAP DIT there is an entry with the common name (cn) as part of dn and 
 * cn has a single backslash character inside. The ldif looks as follows:
 * 
 * dn: cn=temp\\tester,cn=users,dc=mydomain,dc=com
 * objectclass: top
 * objectclass: person
 * objectclass: organizationalPerson
 * objectclass: inetOrgPerson
 * cn: cn=temp\tester
 * sn: tester
 * givenName: temp
 * telephoneNumber: (555)-1234
 *
 */
public class Backslash
{
   public static void main(String args[])
   {
       Hashtable env = new Hashtable();
       env.put(Context.INITIAL_CONTEXT_FACTORY,
                         "com.sun.jndi.ldap.LdapCtxFactory");
       env.put(Context.PROVIDER_URL, "ldap://myServer:389/");
       env.put(Context.SECURITY_AUTHENTICATION, "simple");
       env.put(Context.SECURITY_PRINCIPAL, "cn=admin" );
       env.put(Context.SECURITY_CREDENTIALS, "password" );
       
       DirContext ctx = null;
       try{
         /* Open an LDAP connection for the provided principal and credentials */
         ctx = new InitialLdapContext(env, null);
           
         /* base search */
         SearchControls ctls = new SearchControls();
         ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
           
         /* search */
         String base_dn = "cn=temp\\\\tester,cn=users,dc=mydomain,dc=com";
         NamingEnumeration enu = ctx.search(base_dn, "sn=test*", ctls);
           
         /* process results */
         while(enu.hasMore()){
            SearchResult sr = (SearchResult)enu.next();
            System.out.println("dn: " + base_dn);              
            NamingEnumeration attrs = sr.getAttributes().getAll();
            while(attrs.hasMoreElements()){
              BasicAttribute attr = (BasicAttribute)attrs.nextElement();
              String attrType = attr.getID();
              NamingEnumeration vals = attr.getAll();
              while(vals.hasMoreElements()){
                String attrValue = vals.nextElement().toString();
                System.out.println(attrType + ": " + attrValue);
              }
            }
         }
       }catch(Exception e){
         e.printStackTrace();
       }
   }
}





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.