【发布时间】:2017-01-22 11:03:37
【问题描述】:
我需要向我的 ldap 添加一个新用户条目。以下是我的代码:
javax.naming.Name name = new DistinguishedName("cn=" + userName +",ou=Users,dc=wso2,dc=org");
Attribute objectClass = new BasicAttribute("objectClass");
{
objectClass.add("top");
objectClass.add("inetOrgPerson");
objectClass.add("person");
objectClass.add("organizationalPerson");
}
Attributes userAttributes = new BasicAttributes();
userAttributes.put(objectClass);
userAttributes.put("cn", userName);
userAttributes.put("sn", "abctest");
userAttributes.put(ATTRIBUTE_USER_PASSWORD, password);
LdapTemplate ldapTemplate = (LdapTemplate) SpringBeanFactory
.getBean("ldapTemplate");
ldapTemplate.bind(name, null, userAttributes);
虽然执行这段代码时出现以下异常:
org.apache.cxf.interceptor.Fault: [LDAP: error code 32 - No Such Object];
nested exception is javax.naming.NameNotFoundException:
[LDAP: error code 32 - No Such Object]; remaining name 'cn=myname,ou=Users,dc=wso2,dc=org'
我正在遵循http://kaustuvmaji.blogspot.in/2014/12/simple-example-of-spring-ldap.html 指定的示例代码。有人可以帮助我了解此错误的根本原因或正确的代码。
【问题讨论】:
标签: java ldap spring-ldap