我想添加节点到ldap目录下,但是总报错:
Exception in add():javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn=denis,dc=lily,dc=com'
下面是添加节点的方法代码,请大家帮忙看看哪有问题啊(服务器认证已成功)
public static void add(){
     try{
   String newUserName = "denis";
  
   Attributes attrs = new BasicAttributes(true);
   Attribute objclassSet = new BasicAttribute("objectclass");
   objclassSet.add("top");
   objclassSet.add("person");  
   attrs.put(objclassSet);
   attrs.put(new BasicAttribute("cn", newUserName));
   attrs.put(new BasicAttribute("sn", newUserName));
   
   ctx.createSubcontext("cn=" + newUserName + ",dc=lily,dc=com", attrs);  //添加一个节点
   
  }catch(Exception e){
   System.out.println("Exception in add():"+e);
  }
    }

解决方案 »

  1.   

    唉,怎么没人响应呢?
    程序又出现新的问题了!
    在服务器认证时,原来的程序认证授权是simple,后来认证授权改为none时出现下面错误:
    Exception in add():javax.naming.AuthenticationNotSupportedException: [LDAP: error code 8 - modifications require authentication]; remaining name 'cn=denis,dc=lily,dc=com'
    认证授权改为strong时出现下面错误:
    javax.naming.AuthenticationNotSupportedException: strong
    这又是怎么回事呢?
      

  2.   

    注释掉行“ attrs.put(new BasicAttribute("cn", newUserName)); ”
      

  3.   

    ctx.createSubcontext("cn=" + newUserName + ",dc=lily,dc=com", attrs);
    改为  ctx.createSubcontext("cn=" + newUserName , attrs);