0

I'm in trouble with this error when I change a password or update user's info. I've tried so many codes that are similar each others, but I still got the error. The problem can be a bad CN definition, but should be correct in my case and I'm really sad about this because I cannot face the problem.

  • Connection to the server via LDAP: OK.
  • SSL and cacerts: OK.
  • Add user via code: OK.
  • Fetching all users info: OK.
  • Update user's info: BAD.

Here is a simple code where I try, without success, to update the user's info (description). The user "batman" obviously, exists in AD.

public class ADConnection {

DirContext ctx = null;
String baseName = ",OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL";
String serverIP = "192.168.10.45";
boolean ssl = true;

public ADConnection() {
    try {
        Hashtable ldapEnv = new Hashtable(); 
        ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY,             "com.sun.jndi.ldap.LdapCtxFactory"); 
        if(ssl==true)
        {
            ldapEnv.put(Context.PROVIDER_URL, "ldaps://192.168.10.45:636/dc=softwaredev,dc=local");
            ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl");
        }
        else
        {
            ldapEnv.put(Context.PROVIDER_URL, "ldap://192.168.10.45:389/dc=softwaredev,dc=local");
        }
        ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); 
        ldapEnv.put(Context.SECURITY_PRINCIPAL, new String("softwaredev" + "\\" +     "superadmin"));
        ldapEnv.put(Context.SECURITY_CREDENTIALS, "passw0rd");  
        ctx = new InitialDirContext(ldapEnv); 
    } 
    catch (Exception e) { 
        System.out.println(" bind error: " + e); 
        e.printStackTrace(); 
        System.exit(-1); 
    } 
}

public void updateDescription(String username) {
    try {
      System.out.println("updating...\n");
      ModificationItem[] mods = new ModificationItem[1];
      mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
        new BasicAttribute("description", "batman_description"));
      ctx.modifyAttributes("CN=" + username + baseName, mods);
      System.out.println("update successful!!!");
     }
      catch (Exception e) {
        System.out.println(" update error: " + e);
        System.exit(-1);
      }
  }

public static void main(String[] args) { 
    ADConnection adc = new ADConnection(); 
    adc.updateDescription("batman");
    } 
    }

ERROR: update error: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:

The crash is on the 6th line of code in the function updateDescription. Any suggestions?

3
  • This could be because of your Fully Qualified Domain Name of the user is incorrect. Using any LDAP browser like JXplorer please double check the FQDN of the user and ensure that this is the one that you are using in your code Commented Jun 30, 2014 at 8:33
  • 1
    Ok, I've tried with uPn. The error turns into "BAD_NAME". But if I type uncorrectly the current baseName, the error is still NO_OBJECT. Isn't really strange? Commented Jun 30, 2014 at 8:56
  • The UPN is a different attribute, you need to find the CN attribtue value of the user. Commented Jun 30, 2014 at 9:54

2 Answers 2

5

Looking at your code, and the error message, AD is saying that the DN CN=batman,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL does not exist. This message pertains to the entire DN tree.

This means that either of these objects does not exist:

  • DC=LOCAL
  • DC=SOFTWAREDEV,DC=LOCAL
  • OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL
  • OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL
  • CN=batman,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL

You should check the entire DN for correctness, using an LDAP browser, as the error message does not specify which object does not exist.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to wireshark, I got the error and the last of the list was wrong.
0

According to your code the line would look like this:

ctx.modifyAttributes("CN=batman,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL", mods);

Try it like this, it works for me:

ctx.modifyAttributes("CN=batman,OU=SoftwareV3,OU=SOFTWARE", mods);

I followed the example that can be seen in this link:

http://www.java2s.com/Code/JavaAPI/javax.naming.directory/DirContextmodifyAttributesStringnameintmodopAttributesattrs.htm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.