2015-02-10 80 views
1

使用spring LdapTemplate在組中添加成員的最佳方式是什麼。 我已成功創建用戶並刪除用戶前。 但我想添加成員,然後我面臨問題。Spring Ldaptemplate 2將成員添加到組

加入會員編號:

public boolean addMemberToGroup(List<String> groupList, User user) { 
    boolean isAddedSuccessfully=false; 
    try{ 
     for(int i=0;i<groupList.size();i++){ 
      Name groupDn = buildGroupDn(groupList.get(i)); 
      DirContextOperations ctx = ldapTemplate.lookupContext(groupDn); 
      ctx.addAttributeValue("member",buildPersonDn(user.getUid())); 
      ldapTemplate.update(ctx); 
      } 
     isAddedSuccessfully=true; 
    } 
    catch(Exception e){ 
     isAddedSuccessfully=false; 

    } 
    return isAddedSuccessfully; 
} 

private Name buildGroupDn(String groupName) { 
    return LdapNameBuilder.newInstance("cn=groups").add("cn", groupName).build(); 
} 

private Name buildPersonDn(String userID) { 
    return LdapNameBuilder.newInstance() 
     .add("uid", userID).add("cn", "users") 
     .build(); 

}

例外中addMemberToGroup:Class類org.springframework.ldap.core.DirContextAdapter必須有一流水平接口org.springframework.ldap.odm .annotations.Entry註釋。

請讓我知道我錯過了什麼。

回答