use of alien4cloud.security.model.Group in project alien4cloud by alien4cloud.
the class UserService method updateUserGroupRoles.
/**
* Regenerate the group roles in the user.
*
* @param user the user for which to regenerate the group roles
*/
public void updateUserGroupRoles(User user) {
if (CollectionUtils.isEmpty(user.getGroups())) {
user.setGroupRoles(null);
} else {
Set<String> groupRolesSet = Sets.newHashSet();
for (String groupId : user.getGroups()) {
Group group = alienGroupDao.find(groupId);
if (group == null) {
throw new NotFoundException("Group [" + groupId + "] cannot be found");
}
if (CollectionUtils.isNotEmpty(group.getRoles())) {
groupRolesSet.addAll(group.getRoles());
}
}
user.setGroupRoles(groupRolesSet);
}
alienUserDao.save(user);
}
use of alien4cloud.security.model.Group in project alien4cloud by alien4cloud.
the class GroupService method createGroup.
public String createGroup(String name, String email, String description, Set<String> roles, Set<String> users) throws AlreadyExistException {
checkGroupNameUniqueness(name);
Group group = new Group(name);
group.setId(UUID.randomUUID().toString());
group.setDescription(description);
group.setEmail(email);
if (CollectionUtils.isNotEmpty(roles)) {
Set<String> formatedRoles = Sets.newHashSet();
for (String role : roles) {
formatedRoles.add(Role.getStringFormatedRole(role));
}
group.setRoles(formatedRoles);
}
List<User> usersList = null;
if (CollectionUtils.isNotEmpty(users)) {
usersList = Lists.newArrayList();
Set<String> usersSet = Sets.newHashSet();
for (String username : users) {
usersList.add(userService.retrieveUser(username));
usersSet.add(username);
}
group.setUsers(usersSet);
}
alienGroupDao.save(group);
if (CollectionUtils.isNotEmpty(usersList)) {
for (User user : usersList) {
userService.addGroupToUser(group, user);
}
}
return group.getId();
}
use of alien4cloud.security.model.Group in project alien4cloud by alien4cloud.
the class GroupService method addRoleToGroup.
public void addRoleToGroup(String groupId, String role) {
Group group = retrieveGroup(groupId);
Set<String> rolesSet = group.getRoles() == null ? new HashSet<String>() : group.getRoles();
rolesSet.add(Role.getStringFormatedRole(role));
group.setRoles(rolesSet);
alienGroupDao.save(group);
// update groupRoles in users objects
if (CollectionUtils.isNotEmpty(group.getUsers())) {
for (String username : group.getUsers()) {
userService.addGroupRoleToUser(username, role);
}
}
}
use of alien4cloud.security.model.Group in project alien4cloud by alien4cloud.
the class GroupService method updateGroup.
public void updateGroup(String groupId, UpdateGroupRequest groupUpdateRequest) {
Group group = retrieveGroup(groupId);
String currentGroupName = group.getName();
ReflectionUtil.mergeObject(groupUpdateRequest, group);
if (group.getName() == null || group.getName().isEmpty()) {
throw new InvalidArgumentException("Group's name cannot be set to null or empty");
}
// Check with precedent value
if (!currentGroupName.equals(group.getName())) {
// If group name has changed, must check unicity
checkGroupNameUniqueness(group.getName());
}
alienGroupDao.save(group);
}
use of alien4cloud.security.model.Group in project alien4cloud by alien4cloud.
the class GroupService method deleteGroup.
public void deleteGroup(String groupId) throws IOException, ClassNotFoundException {
Group group = retrieveGroup(groupId);
alienGroupDao.delete(groupId);
publisher.publishEvent(new GroupDeletedEvent(this, group));
}
Aggregations