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);
}
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);
}
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));
}
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());
}
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;
}
Aggregations