【问题标题】:generate uidNumber for Ldap posixAccount with LdapTemplate使用 LdapTemplate 为 Ldap posixAccount 生成 uidNumber
【发布时间】:2013-06-14 23:20:48
【问题描述】:

有人在 Ldap 中创建 posixAccount 时遇到过这个错误吗?

 javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - object class 'posixAccount' requires attribute 'uidNumber']

有没有一种聪明的方法来生成一个唯一的 UidNumber 将创建委托给 Ldap 而不是小心找出唯一性? (例如 SQL Server 中的标识列)

谢谢

这里是我使用的代码:

public class LdapService {

//...
private LdapTemplate ldapTemplate;

public UserInfo save(final UserInfo user) {
    Name dn = buildDn(user);
    ldapTemplate.bind(dn, null, buildUserAttributes(user));

    // Update Groups
    for (String group : user.getGroups()) {
        try {
            DistinguishedName groupDn = new DistinguishedName();
            groupDn.add("ou", "groups");
            groupDn.add("cn", group);
            DirContextOperations context = ldapTemplate
                    .lookupContext(groupDn);
            context.addAttributeValue("memberUid", user.getUid());
            ldapTemplate.modifyAttributes(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return user;
}

private Attributes buildUserAttributes(final UserInfo user) {
    Attributes attrs = new BasicAttributes();
    BasicAttribute ocattr = new BasicAttribute("objectclass");
    ocattr.add("top");
    ocattr.add("inetOrgPerson");
    ocattr.add("posixAccount");
    attrs.put(ocattr);
    attrs.put("givenName", user.getName());
    attrs.put("sn", user.getSurname());
    if (user.getDisplayName() != null)
        attrs.put("cn", user.getDisplayName());
    attrs.put("userPassword", "{SHA}" + this.encrypt(user.getPassword()));
    attrs.put("mail", user.getEmail());

    return attrs;
}
//...
}

【问题讨论】:

    标签: java ldap spring-ldap


    【解决方案1】:

    如果您的服务器支持修改增量请求控制,LDAP 客户端可以使用它在一个原子操作中增加一个整数。另见:LDAP: Modify-Increment Extension

    【讨论】:

    • 您的链接返回 404 :(
    猜你喜欢
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多