2009-05-14 15 views
1
/** 
* 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(); 
     } 
    } 
} 

属性をLDAPにこのコードで名前を変更されていない

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

私はあなたのコードが何をすべきか、今いけないが、例外はあなただけ

に入れてあなたに言ったが、次のように私のエラーリストがあります
cn=John Smith,ou=Sales 

代わりの

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

か?

0

エラーコード32は、オブジェクトが見つからないか、不正なDNパスエラーです。あなたは本当に有効なDNを使用する必要があります。

エラー行: 残りの名前 'cn = name1 name2、ou = mycompany'が値を変更したように出力を表示しましたか、それとも実際のエラーコードですか?

コード内でそのパスを参照する場所が他にないため、奇妙に見えます。私はdc = mydomain、dc = comでドメイン(おそらくAD)を使用していることに注意してください。

あなたはおそらく相対パスで逃げることができますが、RDNを変更しているリネーム中にそのパスを疑うことがあります。どこに変更するのかを正確に知ることが重要です。

関連する問題