Search in sources :

Example 1 with Group

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);
}
Also used : Group(alien4cloud.security.model.Group) NotFoundException(alien4cloud.exception.NotFoundException)

Example 2 with Group

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();
}
Also used : Group(alien4cloud.security.model.Group) User(alien4cloud.security.model.User)

Example 3 with Group

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);
        }
    }
}
Also used : Group(alien4cloud.security.model.Group)

Example 4 with Group

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);
}
Also used : Group(alien4cloud.security.model.Group) InvalidArgumentException(alien4cloud.exception.InvalidArgumentException)

Example 5 with 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));
}
Also used : GroupDeletedEvent(alien4cloud.security.event.GroupDeletedEvent) Group(alien4cloud.security.model.Group)

Aggregations

Group (alien4cloud.security.model.Group)20 Then (cucumber.api.java.en.Then)6 User (alien4cloud.security.model.User)5 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 InvalidArgumentException (alien4cloud.exception.InvalidArgumentException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 Location (alien4cloud.model.orchestrators.locations.Location)1 GroupDeletedEvent (alien4cloud.security.event.GroupDeletedEvent)1 ApiOperation (io.swagger.annotations.ApiOperation)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)1 IdsFilterBuilder (org.elasticsearch.index.query.IdsFilterBuilder)1 EventListener (org.springframework.context.event.EventListener)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1