Skip to content

Commit

Permalink
Remove user from a group
Browse files Browse the repository at this point in the history
  • Loading branch information
Fairuz Wan Ismail committed Dec 26, 2015
1 parent 1bdc267 commit 40e8eaf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/sample/controller/LdapUserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,34 @@ public User addMemberToGroup(@RequestParam(value="group") String group,
return user;
}

@RequestMapping("/test/deletegroup")
@ResponseBody
public User removeMemberFromGroup(@RequestParam(value="group") String group,
@RequestParam(value="uid", defaultValue="test.001") String uid) {
log.info("Testing user add to group");

User user = null;
try {
User _user = new User(uid);
user = ldapUserService.findUser(_user);
} catch (NameNotFoundException e) {
log.error("User not found!!!");
log.error("ERROR", e);
} catch (Exception e) {
log.error("Something unknown happened >>> " + e.getClass().getName());
log.error("ERROR", e);
}

try {
ldapGroupService.removeMemberFromGroup(group, user);
} catch (NameNotFoundException e) {
log.error("Group not found!!!");
log.error("ERROR", e);
} catch (Exception e) {
log.error("Something unknown happened >>> " + e.getClass().getName());
log.error("ERROR", e);
}
return user;
}

}
2 changes: 2 additions & 0 deletions src/main/java/sample/domain/LdapGroupDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public interface LdapGroupDao {

public void addMemberToGroup(String groupName, User user);

public void removeMemberFromGroup(String groupName, User user);

}
9 changes: 9 additions & 0 deletions src/main/java/sample/domain/LdapGroupDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public void addMemberToGroup(String groupName, User user) {
ctx.addAttributeValue("uniqueMember", userDn);
ldapTemplate.modifyAttributes(ctx);
}

public void removeMemberFromGroup(String groupName, User user) {
Name groupDn = buildGroupDn(groupName);
Name userDn = buildUserDn(user.getUid());

DirContextOperations ctx = ldapTemplate.lookupContext(groupDn);
ctx.removeAttributeValue("uniqueMember", userDn);
ldapTemplate.modifyAttributes(ctx);
}


}
4 changes: 4 additions & 0 deletions src/main/java/sample/service/LdapGroupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public void addMemberToGroup(String groupName, User user) {
ldapGroupDao.addMemberToGroup(groupName, user);
}

public void removeMemberFromGroup(String groupName, User user) {
ldapGroupDao.removeMemberFromGroup(groupName, user);
}

}

0 comments on commit 40e8eaf

Please sign in to comment.