This discussion is archived
1 2 Previous Next 17 Replies Latest reply: May 20, 2013 11:41 PM by EJP RSS

javax.naming.InvalidNameException

843793 Newbie
Currently Being Moderated
Hi I have the following problem.
I want to get an object from AD. But every time I get the follwing result after running:
Lookup failed: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001CD, problem 2001 (NO_OBJECT), data 0, best match of:
     'DC=fzi,DC=de'


I ran successfull *ctx.list*() and *ctx.search()* with SubtreeScope. But when I want to lookup(), It doesn't run successfully.

Here is the sample code (but notice that I deleted my pw in Context.SECURITY_CREDENTIALS
:

import java.io.IOException;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.ldap.LdapContext;


public class GetUser {
    public static void main(String[] args) throws IOException {
Hashtable<String, Object> env = new Hashtable<String, Object>();


env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");


String ldapURL = "ldap://ldap.fzi.de:3268/DC=fzi,DC=de";

//connect to my domain controller
env.put(Context.PROVIDER_URL,ldapURL);

//set security credentials, note using simple cleartext authentication
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"kocak@fzi.de");
env.put(Context.SECURITY_CREDENTIALS,"....");

try {

//Create the initial directory context
Context ctx = new InitialContext(env);

LdapContext user = (LdapContext)ctx.lookup("CN=Ugur Kocak,OU=Users,OU=PROST");

System.out.println(user);

ctx.close();


}

catch (NamingException e) {
System.out.println("Lookup failed: " + e);
}
}
}


It would be very nice if someone can help me

Best regards
Ugur

Edited by: ugurkocak1980 on Jan 22, 2010 12:35 PM

Edited by: ugurkocak1980 on Jan 22, 2010 12:36 PM
  • 1. Re: javax.naming.InvalidNameException
    EJP Guru
    Currently Being Moderated
    Re: javax.naming.InvalidNameException
    Lookup failed: javax.naming.NameNotFoundException
    So which is it, InvalidNameException or NameNotFoundException?

    If the latter, you need to add ,DC=fzi,DC=de to the end of your query string.
  • 2. Re: javax.naming.InvalidNameException
    843793 Newbie
    Currently Being Moderated
    Hi,
    thanks for answering.
    I have to test it again. Now I have'nt any access to the AD.
    I will get one on Monday. I will write whether it's that problem.

    Br
    Ugur
  • 3. Re: javax.naming.InvalidNameException
    843793 Newbie
    Currently Being Moderated
    Unfortunately it doesn't work
    I get every time the following output:

    Lookup failed: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001CD, problem 2001 (NO_OBJECT), data 0, best match of:
         'DC=fzi,DC=de'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
  • 4. Re: javax.naming.InvalidNameException
    843793 Newbie
    Currently Being Moderated
    yupii it's done
  • 5. Re: javax.naming.InvalidNameException
    EJP Guru
    Currently Being Moderated
         'DC=fzi,DC=de'
    I told you to append that to your search string ...
  • 6. Re: javax.naming.InvalidNameException
    972794 Newbie
    Currently Being Moderated
    Hi ,
    I am facing the same problem. What is the solution for this?
  • 7. Re: javax.naming.InvalidNameException
    EJP Guru
    Currently Being Moderated
    I am facing the same problem. What is the solution for this?
    Just a crazy thought, but if the problem is the same, the solution is the same too?
  • 8. Re: javax.naming.InvalidNameException
    972794 Newbie
    Currently Being Moderated
    Hi,
    I am getting the same error. But I am not running ctx.list or ctx.search method. I am just trying to change the User password in AD.
               DirContext ldapContext;
            String baseName = "CN=APOPSDC, DC=ispl, DC=com"; 
            String based = " ";
            String serverIP = "apopsdc";
            String modelUsername = "template";
            
            System.out.println("works");
            
             
              Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
                String keystore = "C:\\Program Files\\Java\\jdk1.6.0_26\\jre\\lib\\security\\cacerts";
                System.setProperty("javax.net.ssl.trustStore",keystore); 
                  // the keystore that holds trusted root certificates
               
          
            try {
                                
               
                Hashtable env = new Hashtable(11);
                env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                String ldapURL = "ldap://***********:636";
                env.put(Context.PROVIDER_URL, "ldap://********.636");
                env.put(Context.SECURITY_AUTHENTICATION, "Simple");
                //it can be <domain\\userid> something that you use for windows login
                //it can also be
                String userName = "ispl\\navin.kumar";
                env.put(Context.SECURITY_PRINCIPAL, "************");
                env.put(Context.SECURITY_CREDENTIALS, "********");
                
               
                env.put(Context.SECURITY_PROTOCOL, "ssl");
                //in following property we specify ldap protocol and connection url.
                //generally the port is 389
                
    
                ldapContext = new InitialDirContext(env);
                DirContext ctx = (DirContext)ldapContext;
                System.out.println("Context Sucessfully Initialized");
               
               
                ModificationItem[] mods = new ModificationItem[1];
                mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userpassword" ,"********" ));
                System.out.println("step 3");
                //ldapContext.modifyAttributes("cn=" + username + baseName, mods);
                System.out.println("dn = " + "cn=" + ldapURL + userName);
                ctx.modifyAttributes(based, mods);
                System.out.println("step 4");
                System.out.println("success base");
                ctx.close();  
               
                        
            } catch (Exception e) {
                System.out.println(" bind error: " + e);
                e.printStackTrace();
                System.exit(-1);
            }
    
            }
    When I run this, I am getting the following error :
    "dn = cn=ldap://apopsdc.ispl.com:636ispl\*******
     bind error: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001A8, problem 2001 (NO_OBJECT), data 0, best match of:
         ''
    {code}
    What is the problem here?
    
    Edited by: EJP on 21/02/2013 16:09
    
    Edited by: Infanta on May 20, 2013 11:03 PM
    
    Edited by: Infanta on May 20, 2013 11:05 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  • 9. Re: javax.naming.InvalidNameException
    EJP Guru
    Currently Being Moderated
    String based = " ";
    That cannot possibly be correct. Surely it should be ""?
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    Hasn't been needed since about 2004.
    String keystore = "C:\\Program Files\\Java\\jdk1.6.0_26\\jre\\lib\\security\\cacerts";
    System.setProperty("javax.net.ssl.trustStore",keystore);
    // the keystore that holds trusted root certificates
    All of that accomplishes exactly nothing as it is already the default.
    ctx.modifyAttributes(based, mods);
    That can't possibly be right either. You are modifying a context named " " within the root context. Have a look further up this thread, as I suggested earlier. You have a basename defined but you aren't using it, and you aren't making any use of the user's DN or CN either.
  • 10. Re: javax.naming.InvalidNameException
    972794 Newbie
    Currently Being Moderated
    Hi,
    I have changed my code. Still getting the same error.

    public void tabOut(ValueChangeEvent valueChangeEvent) {
    DirContext ldapContext;
    String baseName = "cn=users, CN=APOPSDC, DC=ispl, DC=com";
    String modelUsername = "template";

    System.out.println("works");

    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    String keystore = "C:\\Program Files\\Java\\jdk1.6.0_26\\jre\\lib\\security\\cacerts";
    System.setProperty("javax.net.ssl.trustStore",keystore);
    // the keystore that holds trusted root certificates


    try {



    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    // String ldapURL = "ldap://apopsdc.ispl.com:636";
    //String ldapURL = "LDAP://192.168.1.3:636";
    //env.put(Context.PROVIDER_URL, "ldap://apopsdc.ispl.com:636");
    env.put(Context.PROVIDER_URL, "ldap://**********:636");
    //env.put(Context.PROVIDER_URL,ldapURL);
    env.put(Context.SECURITY_AUTHENTICATION, "Simple");
    //it can be <domain\\userid> something that you use for windows login
    //it can also be
    String userName = "ispl\\navin.kumar";
    env.put(Context.SECURITY_PRINCIPAL, "**********");
    env.put(Context.SECURITY_CREDENTIALS, "**********");


    env.put(Context.SECURITY_PROTOCOL, "ssl");


    ldapContext = new InitialDirContext(env);
    DirContext ctx = (DirContext)ldapContext;
    System.out.println("Context Sucessfully Initialized");


    ModificationItem[] mods = new ModificationItem[1];
    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userpassword" ,"Aptuit*1" ));
    System.out.println("step 3");
    //ldapContext.modifyAttributes("cn=" + username + baseName, mods);
    //System.out.println("dn = " + "cn=" + ldapURL + userName);
    ldapContext.modifyAttributes("CN=**********,DC=ispl,DC=com", mods); *////ERROR*
    //ctx.modifyAttributes(baseName , mods); *///ERROR*
    System.out.println("step 4");
    System.out.println("success base");
    //ctx.close();


    } catch (Exception e) {
    System.out.println(" bind error: " + e);
    e.printStackTrace();
    System.exit(-1);
    }

    }

    My log file says :

    "Context Sucessfully Initialized
    step 3
    bind error: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001CD, problem 2001 (NO_OBJECT), data 0, best match of:
         'DC=ispl,DC=com' "

    Regards,
    Infanta

    Edited by: Infanta on May 20, 2013 11:05 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
  • 11. Re: javax.naming.InvalidNameException
    EJP Guru
    Currently Being Moderated
    Well part of it is that you are having the same escaping problem as How to add the backslash to the subject. However as you're using JNDI I think you're in luck, you should be construct a javax.naming.ldap.LdapName from your string and pass that to Context.modifyAttributes() as the name parameter instead of the String. At least you may get a better error message ;-)
  • 12. Re: javax.naming.InvalidNameException
    972794 Newbie
    Currently Being Moderated
    Hi,
    I am not sure how to construct that. Can you please elaborate this? In my case, authentication works fine. Only when I change the password, I am getting error messages. That is only in the "modifyAttributes" method I am getting struck. Is it the right way of giving the parameters?


    Regards,
    Infanta
  • 13. Re: javax.naming.InvalidNameException
    EJP Guru
    Currently Being Moderated
    You're getting error messages about the name that you are passing as the first parameter of modifyAttributes(). I've told you how to fix that.
  • 14. Re: javax.naming.InvalidNameException
    972794 Newbie
    Currently Being Moderated
    Hi,

    Its done !! I had problem with my CN details. Now I am able to authenticate. But I am getting different error now. If I give admin rights to a particular user to change the password from active directory, then I am able to change the password for the particular user, my code works fine. otherwise I am not able to change the password for that user. If I do so, I am getting the following error :

    "New Modification
    step 3
    bind error: javax.naming.NoPermissionException: [LDAP: error code 50 - 00002098: SecErr: DSID-03150A48, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0 "

    But then I logged in with the particular user ('dmptest'), and tried to change the password, I was able to.

    My code :

        public void tabOut(ValueChangeEvent valueChangeEvent) {
            DirContext ldapContext;
            String baseName = "cn=users, CN=APOPSDC, DC=ispl, DC=com";
            String modelUsername = "template";
            String userName = "CN=dmptest,CN=Users,DC=ispl,DC=com";
            
            System.out.println("works");
         
           Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
           String keystore = "C:\\Program Files\\Java\\jdk1.6.0_26\\jre\\lib\\security\\cacerts";
           System.setProperty("javax.net.ssl.trustStore",keystore);
        
                   
            try {
                               
              
                Hashtable env = new Hashtable(11);
                env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                env.put(Context.PROVIDER_URL, "ldap://192.168.1.3:636");
                 env.put(Context.SECURITY_AUTHENTICATION, "Simple");
              
                env.put(Context.SECURITY_PRINCIPAL, "**********");
                env.put(Context.SECURITY_CREDENTIALS, "**********
              
               
               
                env.put(Context.SECURITY_PROTOCOL, "ssl");
                System.out.println("it works!!");
                LdapContext ctx = new InitialLdapContext(env,null);
               
                System.out.println("Context Sucessfully Initialized");
                System.out.println(ctx.getEnvironment());
                ModificationItem[] mods = new ModificationItem[1];
    System.out.println("step1");
    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userpassword" ,"Aptuit*1" ));
    System.out.println("New Modification");
    System.out.println("step 3");

    ctx.modifyAttributes(userName, mods);
    System.out.println("step 4");
    System.out.println("success base");



    } catch (Exception e) {
    System.out.println(" bind error: " + e);
    e.printStackTrace();
    System.exit(-1);
    }

    }

    Edited by: Infanta on May 20, 2013 11:06 PM
1 2 Previous Next