怎么向LDAP添加数据
我的LDAP server的配置信息如下:
#######################################################################
# BDB database definitions
#######################################################################
database bdb
suffix "dc=my-domain,dc=com"
rootdn "cn=Manager,dc=my-domain,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw secret
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory %LOCALSTATEDIR%/openldap-data
# Indices to maintain
index objectClass eq
我的客户端程序如下:
Properties env = new Properties();
String ldapURL = "LDAP://192.168.0.36:389/dc=my-domain,dc=com";
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapURL);
LdapContext ctx = null;
try {
ctx = new InitialLdapContext(env, null);
} catch (NamingException e1) {
e1.printStackTrace();
}
try {
String newUserName = "Alex";
BasicAttributes attrs = new BasicAttributes();
BasicAttribute objclassSet = new BasicAttribute("objectclass");
objclassSet.add("person");
objclassSet.add("top");
objclassSet.add("organizationalPerson");
objclassSet.add("inetOrgPerson");
objclassSet.add("wlsUser");
attrs.put(objclassSet);
attrs.put("sn", newUserName);
attrs.put("uid", newUserName);
attrs.put("cn", newUserName);
ctx.createSubcontext("cn=Manager,dc=my-domain,dc=com" , attrs);
} catch (Exception e) {
System.out.println("Exception in add():" + e);
}
运行程序总是报错:
Exception in add():javax.naming.directory.InvalidAttributeValueException: [LDAP: error code 21 - objectclass: value #3 invalid per syntax]; remaining name 'cn=Manager,dc=my-domain,dc=com'
请高手指点下是什么原因,或者提供些学习资料,刚开始接触LDAP,感觉有很多困难,请大家帮忙支持下,非常感谢!