1. 添加一个新的entry
        LDAPAttributeSet attributes = new LDAPAttributeSet();
        LDAPAttribute attribute = null;
        
        String [] objectClass = {"top", "person", "organizationalPerson", "inetOrgPerson"};
        attribute = new LDAPAttribute("objectclass", objectClass);
        attributes.add(attribute);
        
        attribute = new LDAPAttribute("uid", user.getUserId());
        attributes.add(attribute);
        
        attribute = new LDAPAttribute("userpassword", user.getPassword());
        attributes.add(attribute);
        
        Name name = user.getUserInfo().getName();
        
        attribute = new LDAPAttribute("givenname", name.getFirstName());
        attributes.add(attribute);
        
        attribute = new LDAPAttribute("sn", name.getLastName());
        attributes.add(attribute);
        
        attribute = new LDAPAttribute("cn", name.toString());
        attributes.add(attribute);

        LDAPConnection conn = LdapUtils.getAuthenedConnection();
        conn.add(LdapUtils.getDnForUser(userId), attributes);

其中值得注意的是:
a. 在给属性集合添加属性的时候,必须先添加"objectclass"属性,否则会报告 object class vialate 异常。
b. 在使用连接将生成的新entry对象实际加入服务器的时候,必须先使用拥有添加权限的用户authenticate到服务器。
评论
Hejrcc 2007-06-14
你怎么会有 LDAPAttributeSet 这个类的?
用了什么Library?
发表评论

您还没有登录,请登录后发表评论

Frederick
搜索本博客
最近加入圈子
存档
最新评论