title: JAVA ldap error NO_OBJECT
body: <p>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.</p>
  
  <ul>
  <li>Connection to the server via LDAP: <em>OK</em>.</li>
  <li>SSL and cacerts: <em>OK</em>.</li>
  <li>Add user via code: <em>OK</em>.</li>
  <li>Fetching all users info: <em>OK</em>.</li>
  <li>Update user's info: <strong>BAD</strong>.</li>
  </ul>
  
  <p>Here is a simple code where I try, without success, to update the user's info (description).
  The user "batman" obviously, exists in AD.</p>
  
  <pre><code>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");
      } 
      }
  </code></pre>
  
  <p><strong>ERROR:</strong>
  <em>update error: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:</em></p>
  
  <p>The crash is on the 6th line of code in the function updateDescription.
  Any suggestions?</p>