ld.connect("192.168.1.72",389);
ld.authenticate("admin", "abc123");
试一试。
ld.connect("192.168.1.72",389)添加数据时却会出错是因为你根本没有登录呀,你只是用了匿名用户连接而已,当然没权限添加。
另外你可以到图形界面中察看一下,可能域名中还有其它的结构,不止"uid=",可能还有"o=","c=","gid="等等。

解决方案 »

  1.   

    不行哦,他还是提示
    netscape.ldap.LDAPException: error result (32); No such object
      

  2.   

    ldap的用户不简单是名字而已
    一般为
    uid=xxx,ou=xxx,o=xxxx
    建议查查看
      

  3.   

    ld.connect("192.168.1.72",389);
    ld.authenticate("cn=Directory Manager", "22222222");就可以了,22222222是我以前设的密码。但是添加还是不行LDAPAttributeSet attrs = new LDAPAttributeSet();
    attrs.add(attrobj);
    attrs.add(new LDAPAttribute("cn",fullname));
    attrs.add(new LDAPAttribute("giveName",fname));
    attrs.add(new LDAPAttribute("sn",lname));
    attrs.add(new LDAPAttribute("Employeenumber",employeeid));
    attrs.add(new LDAPAttribute("userpassword",password));

    LDAPEntry theEntry = new LDAPEntry(dn,attrs);
    try {
        ld.add(theEntry);
        System.out.println("Added: " + dn);
    } catch (LDAPException lda) {
    }提示出错:netscape.ldap.LDAPException: error result (65); Object class violation
      

  4.   

    需要指定objectclass的
    我以前是这样写的    //add to ldap
      String objectclass_values[] = { "top",
       "person",
       "organizationalPerson",
       "inetOrgPerson",
       "nsLicenseUser",
       "mailRecipient"
       };
      String cn_values[] = {fullName};
      String sn_values[] = {lastName};
      String givenname_values[] = {firstName};
      String email_values[] = {email};
      String telephoneNumber_values[]={phone};
        //let's go!
        LDAPAttributeSet attrs = new LDAPAttributeSet();
        
        //objectclass
        LDAPAttribute attr = new LDAPAttribute( "objectclass" );
        for(int i = 0; i<objectclass_values.length; i++){
          attr.addValue( objectclass_values[i] );
        }
        attrs.add(attr);
        //cn
        attr = new LDAPAttribute("cn");
        for(int i = 0; i<cn_values.length; i++) {
          attr.addValue(cn_values[i]);
        }
        attrs.add(attr);
        //sn
        attr = new LDAPAttribute( "sn" );
        for(int i = 0; i < sn_values.length; i++) {
          attr.addValue( sn_values[i] );
        }
        attrs.add(attr);
        //givenname
        attr = new LDAPAttribute( "givenname" );
        for( int i = 0; i < givenname_values.length; i++ ) {
         attr.addValue( givenname_values[i] );
        }
        attrs.add(attr);
        //password
        attrs.add(new LDAPAttribute("userpassword",password));
        //uid
        attrs.add(new LDAPAttribute("uid",id));
        //email
        attr =new LDAPAttribute("mail");
        for( int i = 0; i < email_values.length; i++ ) {
          System.out.println("DEBUG: " + email_values[i]);
          attr.addValue( email_values[i] );
        }
        attrs.add(attr);
        attr =new LDAPAttribute("telephoneNumber");
        for( int i = 0; i < telephoneNumber_values.length; i++ ) {
          attr.addValue( telephoneNumber_values[i] );
        }
        attrs.add(attr);
        //server about
        //nslicensedfor
        attrs.add(new LDAPAttribute("nslicensedfor","mail"));
        //mailhost
        attrs.add(new LDAPAttribute("mailhost",mailhost));
        //maildeliveryoption
        attrs.add(new LDAPAttribute("maildeliveryoption","mailbox"));
        attrs.add(new LDAPAttribute("title",title));
        String sUnit = String.valueOf(unit);
        String dn = "uid=" + id + ", " + Utils.getLDAPServerRoot(application,sUnit);
        System.out.println("DEBUG: dn" + dn);
        LDAPEntry myEntry = new LDAPEntry(dn, attrs);
      

  5.   

    我最近也在学写这个,不过是用VC,建议去下载一个图形界面的东西,现用它试试,能成功了,再用code试试。我现在正在用的是softerra LDAP Administrator,30天试用版的。
    一点个人经验:要新加entry,dn必须是新entry的dn,而不是新entry的父entry的dn。例如:要往ou=Persons,DC=frontiertech,DC=info加一个用户,root dn打算用用户id,那这个新entry的dn很可能是这样:userid=00000001,ou=Persons,DC=frontiertech,DC=info
    其实你从楼上虫子的代码中也可以看出来。
    还有一点就是和ldap的schema有关系,我现在还无法自己定义objectclass,或者说我自定义的无法加。我已经头痛一星期了,多交流。祝好运。
      

  6.   

    import netscape.ldap.*;
    import netscape.ldap.controls.*;
    import java.util.*;public class addEntry
    {
       public addEntry () { }

    public static void main (String[] argv)
    {
    String uid ="father";
    String fname = "yan";
    String lname = "zhang";
    String password = "abc123";
    String employeeid = "1111111";
    String basedn = "ou=aaa,ou=bbb,ou=ccc,o=test,c=cn";

    String fullname = fname + " " + lname;
    String dn = "uid=" + uid + "," + basedn;
    String [] objclass = {"top","person","organizationalPerson","inetOrgPerson","nslicenseuser"};

    LDAPAttribute attrobj = new LDAPAttribute("objectclass");
    for(int i = 0; i<objclass.length; i++){
    attrobj.addValue( objclass[i] );
    }

    LDAPConnection ld = null; 
    try {
        ld = new LDAPConnection();
    ld.connect("192.168.1.72",389);//,"admin","abc123");
    ld.authenticate("cn=Directory Manager", "22222222");
    } catch (LDAPException e) {
    System.out.println("Connection Error :" + e.toString());
    }
    LDAPAttributeSet attrs = new LDAPAttributeSet();
    attrs.add(attrobj);
    attrs.add(new LDAPAttribute("cn",fullname));
    attrs.add(new LDAPAttribute("giveName",fname));
    attrs.add(new LDAPAttribute("sn",lname));
    attrs.add(new LDAPAttribute("userpassword",password));
    attrs.add(new LDAPAttribute("Employeenumber",employeeid));

    LDAPEntry theEntry = new LDAPEntry(dn,attrs);
    try {
    ld.add(theEntry);
    System.out.println("Added: " + dn);
    } catch (LDAPException lda) {
    System.out.println("Add Error :" + lda.toString());
    System.out.println("Failed to add: " + dn);
    }
    }
    }上面就是我的全部程序,现在connection可以通过了,但是add的时候就会出错提示:
    netscape.ldap.LDAPException: error result (65); Object class violation
      

  7.   

    再次强烈推荐用其他图形界面工具,手工添加试试。
    因为添加的时候受schema限制的。
    另外我发现你一个问题,应该是givenName,不是givename,属性名字错了也不行的。
    还有你的dn是ou=aaa,ou=bbb,ou=ccc,o=test,c=cn,请确定ou=bbb,ou=ccc,o=test,c=cn这个Entry已经存在。