use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testRemoveRoleFromComposition.
@Test
public void testRemoveRoleFromComposition() {
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
IdmRoleCompositionDto roleComposition = getHelper().createRoleComposition(role, subRole);
//
String targetEnvironment = getHelper().createName();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmRoleDto duplicate = roleService.getByBaseCodeAndEnvironment(role.getBaseCode(), targetEnvironment);
//
Assert.assertEquals(1, findAllSubRoles(duplicate).size());
//
roleCompositionService.delete(roleComposition);
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class CustomDuplicateRoleCompositionProcessorIntegrationTest method testDuplicateRole.
/**
* Sub roles has to have the same environment,
* Application sub role is not duplicated automatically - has to exist on the target environment
*/
@Test
public void testDuplicateRole() {
String environment = getHelper().createName();
String otherEnvironment = getHelper().createName();
String targetEnvironment = getHelper().createName();
IdmRoleDto role = getHelper().createRole(null, null, environment);
IdmRoleDto roleSubOne = getHelper().createRole(null, null, environment);
IdmRoleDto otherRoleSub = getHelper().createRole(null, null, otherEnvironment);
IdmRoleDto roleSubTwo = getHelper().createRole(null, null, environment);
IdmRoleDto roleSubOneSubOne = getHelper().createRole(null, null, environment);
IdmRoleDto roleSubOneSubTwo = getHelper().createRole(null, null, environment);
getHelper().createRoleComposition(role, roleSubOne);
getHelper().createRoleComposition(role, otherRoleSub);
getHelper().createRoleComposition(role, roleSubTwo);
getHelper().createRoleComposition(roleSubOne, roleSubOneSubOne);
getHelper().createRoleComposition(roleSubOne, roleSubOneSubTwo);
// prepare some of application role on the target environmant
IdmRoleDto targetRoleSubOneSubOne = getHelper().createRole(null, roleSubOneSubOne.getBaseCode(), targetEnvironment);
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmRoleDto duplicate = roleService.getByBaseCodeAndEnvironment(role.getBaseCode(), targetEnvironment);
List<IdmRoleCompositionDto> directSubRoles = roleCompositionService.findDirectSubRoles(duplicate.getId());
Assert.assertEquals(1, directSubRoles.size());
IdmRoleDto subRole = DtoUtils.getEmbedded(directSubRoles.get(0), IdmRoleComposition_.sub);
Assert.assertEquals(roleSubOne.getBaseCode(), subRole.getBaseCode());
directSubRoles = roleCompositionService.findDirectSubRoles(subRole.getId());
Assert.assertEquals(1, directSubRoles.size());
Assert.assertEquals(targetRoleSubOneSubOne.getId(), directSubRoles.get(0).getSub());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class RoleDeleteBulkActionIntegrationTest method testForceDeleteAsync.
@Test
public void testForceDeleteAsync() {
logout();
loginAsAdmin();
// create identities
String description = getHelper().createName();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
identity.setDescription(description);
IdmIdentityDto identityOne = identityService.save(identity);
identity = getHelper().createIdentity((GuardedString) null);
identity.setDescription(description);
IdmIdentityDto identityTwo = identityService.save(identity);
// create roles
IdmRoleDto role = getHelper().createRole();
IdmRoleDto roleSubOne = getHelper().createRole();
IdmRoleDto roleSubTwo = getHelper().createRole();
IdmRoleDto roleSubSubOne = getHelper().createRole();
// create business roles
IdmRoleCompositionDto compositionOne = getHelper().createRoleComposition(role, roleSubOne);
IdmRoleCompositionDto compositionTwo = getHelper().createRoleComposition(role, roleSubTwo);
IdmRoleCompositionDto compositionThree = getHelper().createRoleComposition(roleSubOne, roleSubSubOne);
// create automatic roles - by tree and by attribute too
IdmAutomaticRoleAttributeDto automaticRoleOne = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRoleOne.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, description);
IdmAutomaticRoleAttributeDto automaticRoleTwo = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRoleTwo.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, description);
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identityOne);
contract.setWorkPosition(treeNode.getId());
contractService.save(contract);
contract = getHelper().getPrimeContract(identityTwo);
contract.setWorkPosition(treeNode.getId());
contractService.save(contract);
IdmRoleTreeNodeDto automaticRoleThree = getHelper().createRoleTreeNode(role, treeNode, false);
IdmRoleTreeNodeDto automaticRoleFour = getHelper().createRoleTreeNode(role, treeNode, false);
// create manuallyAssigned roles
getHelper().createIdentityRole(identityOne, role);
getHelper().createIdentityRole(identityOne, role);
getHelper().createIdentityRole(identityTwo, role);
getHelper().createIdentityRole(identityTwo, role);
Assert.assertEquals(24, identityRoleService.findAllByIdentity(identityOne.getId()).size());
Assert.assertEquals(24, identityRoleService.findAllByIdentity(identityTwo.getId()).size());
// remove role async
try {
getHelper().enableAsynchronousProcessing();
Map<String, Object> properties = new HashMap<>();
properties.put(RoleProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
// delete by bulk action
IdmBulkActionDto bulkAction = this.findBulkAction(IdmRole.class, RoleDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
getHelper().waitForResult(res -> {
return roleService.get(role) != null;
});
checkResultLrt(processAction, 1l, 0l, 0l);
//
Assert.assertTrue(identityRoleService.findAllByIdentity(identityOne.getId()).isEmpty());
Assert.assertTrue(identityRoleService.findAllByIdentity(identityTwo.getId()).isEmpty());
Assert.assertNull(roleCompositionService.get(compositionOne));
Assert.assertNull(roleCompositionService.get(compositionTwo));
Assert.assertNotNull(roleCompositionService.get(compositionThree));
Assert.assertNull(automaticRoleAttributeService.get(automaticRoleOne));
Assert.assertNull(automaticRoleAttributeService.get(automaticRoleTwo));
Assert.assertNull(roleTreeNodeService.get(automaticRoleThree));
Assert.assertNull(roleTreeNodeService.get(automaticRoleFour));
Assert.assertNull(roleService.get(role));
Assert.assertNotNull(roleService.get(roleSubOne));
Assert.assertNotNull(roleService.get(roleSubTwo));
Assert.assertNotNull(roleService.get(roleSubSubOne));
} finally {
getHelper().disableAsynchronousProcessing();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testAssignRolesPreventCyclesByRequest.
@Test
public void testAssignRolesPreventCyclesByRequest() {
IdmRoleDto superior = getHelper().createRole();
IdmRoleDto subOne = getHelper().createRole();
IdmRoleDto subTwo = getHelper().createRole();
IdmRoleCompositionDto subOneComposition = getHelper().createRoleComposition(superior, subOne);
IdmRoleCompositionDto subTwoComposition = getHelper().createRoleComposition(subOne, subTwo);
IdmRoleCompositionDto cyclicComposition = getHelper().createRoleComposition(subTwo, superior);
//
// find all sub roles
List<IdmRoleCompositionDto> allSubRoles = service.findAllSubRoles(superior.getId());
Assert.assertEquals(2, allSubRoles.size());
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subOneComposition.getId())));
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subTwoComposition.getId())));
//
// assign superior role
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleRequestDto roleRequest = getHelper().createRoleRequest(identity, superior);
//
getHelper().executeRequest(roleRequest, false);
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(superior.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subTwo.getId())));
//
// remove role composition
service.delete(cyclicComposition);
//
allSubRoles = service.findAllSubRoles(superior.getId());
Assert.assertEquals(2, allSubRoles.size());
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subOneComposition.getId())));
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subTwoComposition.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(superior.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subTwo.getId())));
//
cyclicComposition = getHelper().createRoleComposition(subTwo, superior);
//
allSubRoles = service.findAllSubRoles(superior.getId());
Assert.assertEquals(2, allSubRoles.size());
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subOneComposition.getId())));
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subTwoComposition.getId())));
// role is asssigned in the middle => cycle is detected one step after
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(6, assignedRoles.size());
Assert.assertEquals(2, assignedRoles.stream().filter(ir -> ir.getRole().equals(superior.getId())).count());
Assert.assertEquals(2, assignedRoles.stream().filter(ir -> ir.getRole().equals(subOne.getId())).count());
Assert.assertEquals(2, assignedRoles.stream().filter(ir -> ir.getRole().equals(subTwo.getId())).count());
//
// remove role composition again
service.delete(cyclicComposition);
//
allSubRoles = service.findAllSubRoles(superior.getId());
Assert.assertEquals(2, allSubRoles.size());
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subOneComposition.getId())));
Assert.assertTrue(allSubRoles.stream().anyMatch(c -> c.getId().equals(subTwoComposition.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(superior.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subTwo.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testGetDistinctRoles.
@Test
@Transactional
public void testGetDistinctRoles() {
// null => empty
Assert.assertTrue(service.getDistinctRoles(null).isEmpty());
Assert.assertTrue(service.getDistinctRoles(new ArrayList<>()).isEmpty());
//
// prepare role composition
IdmRoleDto superior = getHelper().createRole();
IdmRoleDto subOne = getHelper().createRole();
IdmRoleDto subTwo = getHelper().createRole();
IdmRoleDto subOneSub = getHelper().createRole();
IdmRoleDto subOneSubSub = getHelper().createRole();
List<IdmRoleCompositionDto> compositions = new ArrayList<>();
compositions.add(getHelper().createRoleComposition(superior, subOne));
compositions.add(getHelper().createRoleComposition(superior, subTwo));
compositions.add(getHelper().createRoleComposition(subOne, subOneSub));
compositions.add(getHelper().createRoleComposition(subOneSub, subOneSubSub));
//
Set<UUID> distinctRoles = service.getDistinctRoles(compositions);
//
Assert.assertEquals(5, distinctRoles.size());
Assert.assertTrue(distinctRoles.stream().anyMatch(r -> r.equals(superior.getId())));
Assert.assertTrue(distinctRoles.stream().anyMatch(r -> r.equals(subOne.getId())));
Assert.assertTrue(distinctRoles.stream().anyMatch(r -> r.equals(subTwo.getId())));
Assert.assertTrue(distinctRoles.stream().anyMatch(r -> r.equals(subOneSub.getId())));
Assert.assertTrue(distinctRoles.stream().anyMatch(r -> r.equals(subOneSubSub.getId())));
}
Aggregations