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注释。
请让我知道我错过了什么。