我正在开发一个应用程序spring-boot,用于使用LdapTemplate获取Ldap存储库的用户信息。
我使用用户电子邮件作为uid,当用户更新他的电子邮件时我也必须更新他的uid。问题是下面的方法适用于所有Person字段,但不适用于UID。我收到一个错误:
reduce
这是一个片段:
let shortDescriptor = NSSortDescriptor(key: key, ascending: ascending)
fetchedResultViewController.fetchRequest.sortDescriptors = [shortDescriptor]
NSFetchedResultsController<NSFetchRequestResult>.deleteCache(withName: fetchedResultViewController.cacheName)
do {
try fetchedResultViewController?.performFetch()
} catch let error as NSError {
print("Error in fetch \(error)")
}
BuildDn:
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);
}
你有什么想法来修复这个错误吗?
祝你好运
答案 0 :(得分:3)
您无法对uid字段执行修改,而是必须重命名记录以更新uid。
像这样:
ldapTemplate.rename("uid=oldUid,ou=People,dc=example,dc=com", "uid=newUid,ou=People,dc=example,dc=com")
而不是
ldapTemplate.modifyAttributes(context);
。
答案 1 :(得分:0)
Define the configuratons for LdapContextSource and LdapTemplate
Name dn = LdapNameBuilder.newInstance().add("uid", uid).build();
Name dnNew = LdapNameBuilder.newInstance().add("uid", newUid).build();
ldapTemplate.rename(dn, dnNew);
这将更新uid。
void rename(Name oldDn, Name newDn)
将LDAP树中的条目移动到新位置。
答案 2 :(得分:0)
ldapTemplate的重命名方法以某种方式起作用,但是我将如何重命名属性本身?:
@Test(expected = SchemaViolationException.class)
public void testModifyRdnUsingDirContext() {
LdapName name = LdapNameBuilder.newInstance()
.add("ou", "people")
.add("uid", "test")
.build();
LdapName newName = LdapNameBuilder.newInstance()
.add("ou", "people")
.add("uid", "test1")
.build();
// seems disfuctional, because it is not possible to change the value
// of the uid attribute to the new one beforehand or afterwards. This
// problem might be unboundID (embedded ldap server) specific.
ldapTemplate.rename(name, newName);
DirContextOperations context = ldapTemplate.lookupContext(newName);
context.setAttributeValue("uid", "test1");
ldapTemplate.modifyAttributes(context);
}