The attribute is not renamed by this code in LDAP

/**
 * ModifyRDN .java
 * Sample code to demostrate how ModifyRDN/ModifyDN works.
 */

import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

public class ModifyRDN 
{
    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://myLdapServer:389/dc=myDomain,dc=com");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "cn=directory manager");
        env.put(Context.SECURITY_CREDENTIALS, "password");

        /*
          Whether the old RDN attribute values are to be retained 
          as attributes of the entry, or deleted from the entry
        */
        env.put("java.naming.ldap.deleteRDN", "true");  // default is 'true'

        try {
            /* Create the initial context */
            DirContext ctx = new InitialDirContext(env);

            ctx.rename("cn=John Smith,ou=Sales,ou=People", 
                       "cn=John Cougar Smith,ou=Sales,ou=People");

            /* Close the context when it done */
            ctx.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

      

My error list looks like this

javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn=name1 name2,ou=mycompany'
    at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3025)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2946)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2752)
    at com.sun.jndi.ldap.LdapCtx.c_rename(LdapCtx.java:700)
    at com.sun.jndi.toolkit.ctx.ComponentContext.p_rename(ComponentContext.java:708)
    at com.sun.jndi.toolkit.ctx.PartialCompositeContext.rename(PartialCompositeContext.java:266)
    at com.sun.jndi.toolkit.ctx.PartialCompositeContext.rename(PartialCompositeContext.java:255)
    at javax.naming.InitialContext.rename(InitialContext.java:395)
    at ModifyRDN.main(ModifyRDN.java:22)

      

+1


a source to share


2 answers


I won't do what the code is supposed to do now, but the exception tells you that you only insert

cn=John Smith,ou=Sales

      

instead



cn=John Smith,ou=Sales,ou=People

      

or not?

+1


a source


Error code 32 is an object not found, or an invalid DN path error. You must give it a real and valid DN to use.

Did you send the print message so that the error line: the remaining name 'cn = name1 name2, ou = mycompany' has changed values ​​or is it a real error code?



This looks odd since you don't reference this path elsewhere in your code. I note that you are using a domain (probably AD) with dc = mydomain, dc = com.

You can probably get away with relative paths, but I doubt that during renaming where you change the RDN, it is important to know exactly what you are changing (and implicitly) there.

0


a source







All Articles