如何在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.10.251:389/dc=my-domain,dc=com";
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
...然后是用户名,密码
用户名是:cn=manager,dc=my-domain,dc=com
密码就没什么了
env.put(Context.PROVIDER_URL, ldapURL);
DirContext ctx = null;
try {
ctx = new ...Context(env);
} catch (NamingException e1) {
e1.printStackTrace();
}
..以上都是连接LDAP,没问题————————————
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");
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(e);
}
运行程序总是报错:
javax.naming.directory.InvalidAttributeValueException: [LDAP: error code 21 - objectclass: value #3 invalid per syntax]; remaining name 'cn=manager,dc=my-domain,dc=com'
请高手指点下是什么原因,或者提供些学习资料,刚开始接触LDAP,感觉有很多困难,请大家帮忙支持下,非常感谢!