2013-06-14 4 views
1

누군가 Ldap의 posixAccount에서이 오류를 이미 발견 했습니까? Ldap에 대한 uidNumber 생성 LdapTemplate을 사용하는 posixAccount

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

대신 고유성을 찾아 돌보는의 LDAP에 작성을 위임 고유 UidNumber를 생성하는 현명한 방법이 있나요?

감사 (부여 됨으로써 SQL Server의 ID 열 등) 여기

코드 내가 사용 : 서버가 수정 - 증가 요청 제어를 지원

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; 
} 
//... 
} 

답변

0

경우, LDAP 클라이언트는 것을 사용할 수있다 하나의 원자 연산에서 정수를 증가시킵니다. 참조 : LDAP: Modify-Increment Extension.