我使用LdapTemplate对LDAP库开发应用程序的春天启动了获取用户信息。
我使用的用户电子邮件作为UID,当用户更新他的电子邮件,我必须得更新自己的UID。问题是,下面的工作方法,对所有的人域而不是UID。我得到一个错误:
LDAP: error code 64 - value of naming attribute 'uid' is not present in entry
这是一个片段:
public void updateUser(Person p) throws InvalidNameException {
Name dn = buildDn(p);
DirContextOperations context = ldapTemplate.lookupContext(dn);
LdapMapper.mapToContext(p, context);
ldapTemplate.modifyAttributes(context);
}
BuildDn:
public Name buildDn(Person p) throws InvalidNameException {
List lstRdn = new ArrayList();
lstRdn.add(new Rdn("dc", "priv"));
lstRdn.add(new Rdn("dc", "com"));
lstRdn.add(new Rdn("ou", "customers"));
lstRdn.add(new Rdn("ou", "myusers");
lstRdn.add(new Rdn("uid", "oldUid"));
Name name = new LdapName(lstRdn);
return name;
}
映射器
public static void mapToContext(Person p, DirContextOperations context) {
context.setAttributeValues("objectclass", new String[] { "top", "person", "inetOrgPerson", "organizationalPerson" });
context.setAttributeValue("cn", p.getFirstName());
context.setAttributeValue("sn", p.getLastName());
context.setAttributeValue("mail", p.getEmail());
context.setAttributeValue("userPassword", p.getPassword());
context.setAttributeValue("uid", "NewUid");
}
你有什么想法来修复这个bug?
最好的祝福