use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testCRUDContractWithAutomaticRoles.
@Test
public void testCRUDContractWithAutomaticRoles() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contractToCreate = service.getPrimeContract(identity.getId());
contractToCreate.setIdentity(identity.getId());
contractToCreate.setValidFrom(LocalDate.now().minusDays(1));
contractToCreate.setValidTill(LocalDate.now().plusMonths(1));
contractToCreate.setWorkPosition(nodeD.getId());
contractToCreate.setMain(true);
contractToCreate.setDescription("test-node-d");
service.save(contractToCreate);
//
IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
//
// test after create
Assert.assertEquals(nodeD.getId(), contract.getWorkPosition());
Assert.assertEquals("test-node-d", contract.getDescription());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().allMatch(ir -> contract.getValidFrom().equals(ir.getValidFrom())));
Assert.assertTrue(identityRoles.stream().allMatch(ir -> contract.getValidTill().equals(ir.getValidTill())));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(3, identityRoles.size());
//
// test after delete
service.delete(contract);
assertTrue(identityRoleService.findAllByIdentity(identity.getId()).isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testAutomaticRolesRemovalAfterContractEnds.
@Test
public void testAutomaticRolesRemovalAfterContractEnds() {
// automatic roles by tree structure
prepareAutomaticRoles();
// automatic role by attribute on contract
String autoPosition = getHelper().createName();
IdmRoleDto autoAttributeRole = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(autoAttributeRole.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, autoPosition);
//
// prepare identity, contract, direct roles and automatic roles
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
contract.setIdentity(identity.getId());
contract.setValidFrom(LocalDate.now().minusDays(1));
contract.setValidTill(LocalDate.now().plusMonths(1));
contract.setWorkPosition(nodeD.getId());
contract.setMain(true);
contract.setDescription("test-node-d");
contract.setPosition(autoPosition);
contract = service.save(contract);
UUID contractId = contract.getId();
IdmRoleDto directRole = getHelper().createRole();
getHelper().createIdentityRole(contract, directRole);
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(5, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return directRole.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return autoAttributeRole.getId().equals(ir.getRole());
}));
//
try {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// end contract - all roles should be removed, after asynchronous role request ends
contract.setValidTill(LocalDate.now().minusDays(1));
contract = service.save(contract);
//
Assert.assertFalse(contract.isValidNowOrInFuture());
//
getHelper().waitForResult(res -> {
return !identityRoleService.findAllByContract(contractId).isEmpty();
}, 300, Integer.MAX_VALUE);
getHelper().waitForResult(res -> {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setRunning(Boolean.TRUE);
//
return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
});
//
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertTrue(identityRoles.isEmpty());
//
service.delete(contract);
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testAssignRolesPreventCyclesSameSuperiorAsSub.
@Test
@Transactional
public void testAssignRolesPreventCyclesSameSuperiorAsSub() {
IdmRoleDto superior = getHelper().createRole();
getHelper().createRoleComposition(superior, superior);
//
// assign superior role
IdmIdentityDto identity = getHelper().createIdentity();
getHelper().createIdentityRole(identity, superior);
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(superior.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testAssignRolesDuplicates.
@Test
public void testAssignRolesDuplicates() {
IdmRoleDto superior = getHelper().createRole();
IdmRoleDto subOne = getHelper().createRole();
IdmRoleDto subTwo = getHelper().createRole();
IdmRoleDto subOneOne = getHelper().createRole();
IdmRoleDto subSubOneOne = getHelper().createRole();
getHelper().createRoleComposition(superior, subOne);
getHelper().createRoleComposition(superior, subTwo);
getHelper().createRoleComposition(subOne, subOneOne);
IdmRoleCompositionDto cyclicComposition = getHelper().createRoleComposition(subTwo, subOneOne);
getHelper().createRoleComposition(subOneOne, subSubOneOne);
//
// find all sub roles
List<IdmRoleCompositionDto> allSubRoles = service.findAllSubRoles(superior.getId());
Assert.assertEquals(6, allSubRoles.size());
//
// 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(7, 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())));
Assert.assertEquals(2, assignedRoles.stream().filter(ir -> ir.getRole().equals(subOneOne.getId())).count());
Assert.assertEquals(2, assignedRoles.stream().filter(ir -> ir.getRole().equals(subSubOneOne.getId())).count());
//
// remove role composition
service.delete(cyclicComposition);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(5, 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())));
Assert.assertEquals(1, assignedRoles.stream().filter(ir -> ir.getRole().equals(subOneOne.getId())).count());
Assert.assertEquals(1, assignedRoles.stream().filter(ir -> ir.getRole().equals(subSubOneOne.getId())).count());
//
// create again
cyclicComposition = getHelper().createRoleComposition(subTwo, subOneOne);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(7, 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())));
Assert.assertEquals(2, assignedRoles.stream().filter(ir -> ir.getRole().equals(subOneOne.getId())).count());
Assert.assertEquals(2, assignedRoles.stream().filter(ir -> ir.getRole().equals(subSubOneOne.getId())).count());
//
// remove again
service.delete(cyclicComposition);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(5, 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())));
Assert.assertEquals(1, assignedRoles.stream().filter(ir -> ir.getRole().equals(subOneOne.getId())).count());
Assert.assertEquals(1, assignedRoles.stream().filter(ir -> ir.getRole().equals(subSubOneOne.getId())).count());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testAssignRolesPreventCyclesSameSuperiorAsSubByRequest.
@Test
@Transactional
public void testAssignRolesPreventCyclesSameSuperiorAsSubByRequest() {
IdmRoleDto superior = getHelper().createRole();
getHelper().createRoleComposition(superior, superior);
//
List<IdmRoleCompositionDto> allSubRoles = service.findAllSubRoles(superior.getId());
Assert.assertTrue(allSubRoles.isEmpty());
//
// 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(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(superior.getId())));
}
Aggregations