Search in sources :

Example 1 with Role

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

the class GroupServiceImpl method addRoles.

public void addRoles(TGroup group, List<TRole> roles) {
    Group attachedGroup = groupRepository.refreshWithOptimisticLocking(group.getId(), group.getVersion());
    Collection<Role> attachedRoles = roles.stream().map(r -> roleRepository.refreshWithOptimisticLocking(r.getId(), r.getVersion())).collect(Collectors.toList());
    attachedGroup.addRoles(attachedRoles);
}
Also used : TRole(org.simbasecurity.api.service.thrift.TRole) RoleRepository(org.simbasecurity.core.domain.repository.RoleRepository) Role(org.simbasecurity.core.domain.Role) TGroup(org.simbasecurity.api.service.thrift.TGroup) Group(org.simbasecurity.core.domain.Group) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) TUser(org.simbasecurity.api.service.thrift.TUser) GroupRepository(org.simbasecurity.core.domain.repository.GroupRepository) List(java.util.List) Service(org.springframework.stereotype.Service) GroupService(org.simbasecurity.api.service.thrift.GroupService) ThriftAssembler(org.simbasecurity.core.service.thrift.ThriftAssembler) Transactional(org.springframework.transaction.annotation.Transactional) 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)

Example 2 with Role

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

the class GroupServiceImpl method removeRole.

public void removeRole(TGroup group, TRole role) {
    Role attachedRole = roleRepository.refreshWithOptimisticLocking(role.getId(), role.getVersion());
    Group attachedGroup = groupRepository.refreshWithOptimisticLocking(group.getId(), group.getVersion());
    attachedGroup.removeRole(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)

Example 3 with Role

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

the class RoleManagerServiceTest method setup.

@Before
public void setup() {
    GlobalContext.initialize(locator);
    when(locator.locate(UserValidator.class)).thenReturn(userValidator);
    when(locator.locate(PasswordValidator.class)).thenReturn(passwordValidator);
    when(locator.locate(ConfigurationServiceImpl.class)).thenReturn(configurationService);
    UserEntity userEntity1 = new UserEntity("user-1");
    UserEntity userEntity2 = new UserEntity("user-2");
    ReflectionUtil.setField(entityFilterService, "filters", filterServices);
    roleEntity1.addPolicy(policyEntity1);
    roleEntity2.addPolicy(policyEntity2);
    roleEntity3.addPolicy(policyEntity1);
    roleEntity3.addPolicy(policyEntity2);
    roleEntity1.addUser(userEntity1);
    roleEntity2.addUser(userEntity2);
    roleEntity3.addUser(userEntity1);
    roleEntity3.addUser(userEntity2);
    Collection<Role> roles = asList(roleEntity1, roleEntity2, roleEntity3);
    when(roleRepository.findAll()).thenReturn(roles);
    when(roleRepository.lookUp(roleDTO1)).thenReturn(roleEntity1);
    when(roleRepository.lookUp(roleDTO2)).thenReturn(roleEntity2);
    when(roleRepository.lookUp(roleDTO3)).thenReturn(roleEntity3);
    when(policyRepository.findNotLinked(roleEntity1)).thenReturn(singletonList(policyEntity2));
    when(policyRepository.findNotLinked(roleEntity2)).thenReturn(singletonList(policyEntity1));
    when(policyRepository.findNotLinked(roleEntity3)).thenReturn(emptyList());
    when(policyRepository.findForRole(roleEntity1)).thenReturn(singletonList(policyEntity1));
    when(policyRepository.findForRole(roleEntity2)).thenReturn(singletonList(policyEntity2));
    when(policyRepository.findForRole(roleEntity3)).thenReturn(asList(policyEntity1, policyEntity2));
    when(userRepository.findNotLinked(roleEntity1)).thenReturn(singletonList(userEntity2));
    when(userRepository.findNotLinked(roleEntity2)).thenReturn(singletonList(userEntity1));
    when(userRepository.findNotLinked(roleEntity3)).thenReturn(emptyList());
    when(userRepository.findForRole(roleEntity1)).thenReturn(singletonList(userEntity1));
    when(userRepository.findForRole(roleEntity2)).thenReturn(singletonList(userEntity2));
    when(userRepository.findForRole(roleEntity3)).thenReturn(asList(userEntity1, userEntity2));
}
Also used : Role(org.simbasecurity.core.domain.Role) UserEntity(org.simbasecurity.core.domain.UserEntity) Before(org.junit.Before)

Example 4 with Role

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

the class RoleDTOAssemblerTest method testAssembleSingleRole.

@Test
public void testAssembleSingleRole() {
    Role role = new RoleEntity("role name");
    RoleDTO roleData = RoleDTOAssembler.assemble(role);
    assertNotNull(roleData);
    assertEquals(0, roleData.getId());
    assertEquals(role.getName(), roleData.getName());
    assertEquals(0, role.getId());
    assertEquals(0, role.getVersion());
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) RoleDTO(org.simbasecurity.core.service.manager.dto.RoleDTO) Test(org.junit.Test)

Example 5 with Role

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

the class RuleDatabaseRepositoryTest method setupWithGroups.

private ResourceRule setupWithGroups() {
    User user = new UserEntity(USER_VIA_GROUP);
    Role role = new RoleEntity("role2");
    Group group = new GroupEntity("groupName", "cn");
    Policy policy = new PolicyEntity("policy2");
    ResourceRule resourceRuleEntity = new ResourceRuleEntity("resrule2");
    resourceRuleEntity.setResourceName("resname2");
    urlRuleEntityViaGroup = new URLRuleEntity("urlrule2");
    persistAndRefresh(user, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
    persistAndRefresh(user, group, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
    policy.addRule(resourceRuleEntity);
    policy.addRule(urlRuleEntityViaGroup);
    role.addPolicy(policy);
    group.addRole(role);
    user.addGroup(group);
    return resourceRuleEntity;
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) Policy(org.simbasecurity.core.domain.Policy) Group(org.simbasecurity.core.domain.Group) User(org.simbasecurity.core.domain.User) GroupEntity(org.simbasecurity.core.domain.GroupEntity) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) ResourceRule(org.simbasecurity.core.domain.ResourceRule) ResourceRuleEntity(org.simbasecurity.core.domain.ResourceRuleEntity) UserEntity(org.simbasecurity.core.domain.UserEntity) URLRuleEntity(org.simbasecurity.core.domain.URLRuleEntity)

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