【问题标题】:Attribute is not being renamed by this code in LDAPLDAP 中的此代码未重命名属性
【发布时间】:2010-10-26 03:46:15
【问题描述】:
/**
 * 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's done */
            ctx.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我的错误列表如下

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)

【问题讨论】:

    标签: eclipse jakarta-ee ldap jndi openldap


    【解决方案1】:

    我现在不知道你的代码应该做什么,但是异常告诉你你只输入了

    cn=John Smith,ou=Sales
    

    而不是

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

    还是不行?

    【讨论】:

      【解决方案2】:

      错误代码 32 是找不到对象,或错误的 DN 路径错误。您需要为其提供一个真实有效的 DN 才能使用。

      您是否对输出进行了处理,使得错误行: 剩余名称 'cn=name1 name2,ou=mycompany' 更改了值,还是真正的错误代码?

      看起来很奇怪,因为您在代码中没有其他地方引用该路径。我注意到您正在使用 dc=mydomain,dc=com 的域(可能是 AD)。

      您可能可以摆脱相对路径,但我怀疑在重命名期间,您正在更改 RDN,确切地知道您正在(隐式)更改的位置很重要。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-28
        • 1970-01-01
        • 1970-01-01
        • 2012-07-25
        • 2013-02-12
        • 2016-06-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多