Search in sources :

Example 6 with Role

use of org.simbasecurity.core.domain.Role in project simba-os by cegeka.

the class PolicyManagerService method addRoles.

@RequestMapping("addRoles")
@ResponseBody
public void addRoles(@JsonBody("policy") PolicyDTO policy, @JsonBody("roles") Set<RoleDTO> roles) {
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    Collection<Role> attachedRoles = roleRepository.refreshWithOptimisticLocking(roles);
    attachedPolicy.addRoles(attachedRoles);
}
Also used : Policy(org.simbasecurity.core.domain.Policy) Role(org.simbasecurity.core.domain.Role) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with Role

use of org.simbasecurity.core.domain.Role in project simba-os by cegeka.

the class RoleManagerService method removePolicy.

@RequestMapping("removePolicy")
@ResponseBody
public void removePolicy(@JsonBody("role") RoleDTO role, @JsonBody("policy") PolicyDTO policy) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role);
    Policy attachedPolicy = policyRepository.refreshWithOptimisticLocking(policy);
    attachedRole.removePolicy(attachedPolicy);
    roleRepository.persist(attachedRole);
}
Also used : Role(org.simbasecurity.core.domain.Role) Policy(org.simbasecurity.core.domain.Policy) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with Role

use of org.simbasecurity.core.domain.Role in project simba-os by cegeka.

the class RoleManagerService method createRole.

@RequestMapping("createRole")
@ResponseBody
public RoleDTO createRole(@JsonBody("roleName") String roleName) throws ValidationException {
    DTOValidator.assertValidString("createRole", roleName);
    if (roleRepository.findByName(roleName) != null) {
        throw new IllegalArgumentException("Role with name " + roleName + " already exists");
    }
    Role newRole = RoleAssembler.createRole(roleName);
    roleRepository.persist(newRole);
    return RoleDTOAssembler.assemble(newRole);
}
Also used : Role(org.simbasecurity.core.domain.Role) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with Role

use of org.simbasecurity.core.domain.Role in project simba-os by cegeka.

the class RoleManagerService method addUsers.

@RequestMapping("addUsers")
@ResponseBody
public void addUsers(@JsonBody("role") RoleDTO role, @JsonBody("users") List<UserDTO> users) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role);
    Collection<User> attachedUsers = userRepository.refreshWithOptimisticLocking(users);
    attachedRole.addUsers(attachedUsers);
    roleRepository.persist(attachedRole);
}
Also used : Role(org.simbasecurity.core.domain.Role) User(org.simbasecurity.core.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with Role

use of org.simbasecurity.core.domain.Role in project simba-os by cegeka.

the class GroupServiceImpl method addRole.

public void addRole(TGroup group, TRole role) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role.getId(), role.getVersion());
    Group attachedGroup = groupRepository.refreshWithOptimisticLocking(group.getId(), group.getVersion());
    attachedGroup.addRole(attachedRole);
}
Also used : TRole(org.simbasecurity.api.service.thrift.TRole) Role(org.simbasecurity.core.domain.Role) TGroup(org.simbasecurity.api.service.thrift.TGroup) Group(org.simbasecurity.core.domain.Group)

Aggregations

Role (org.simbasecurity.core.domain.Role)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 Policy (org.simbasecurity.core.domain.Policy)6 Group (org.simbasecurity.core.domain.Group)4 TGroup (org.simbasecurity.api.service.thrift.TGroup)3 TRole (org.simbasecurity.api.service.thrift.TRole)3 RoleEntity (org.simbasecurity.core.domain.RoleEntity)3 User (org.simbasecurity.core.domain.User)3 Test (org.junit.Test)2 UserEntity (org.simbasecurity.core.domain.UserEntity)2 RoleDTO (org.simbasecurity.core.service.manager.dto.RoleDTO)2 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 GroupService (org.simbasecurity.api.service.thrift.GroupService)1 TUser (org.simbasecurity.api.service.thrift.TUser)1 GroupEntity (org.simbasecurity.core.domain.GroupEntity)1 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)1