use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testReferentialIntegrityOnRole.
@Test(expected = ResultCodeException.class)
public void testReferentialIntegrityOnRole() {
// prepare data
IdmRoleDto role = getHelper().createRole();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
// automatic role
IdmRoleTreeNodeDto roleTreeNode = getHelper().createRoleTreeNode(role, treeNode, false);
//
assertNotNull(roleTreeNode.getId());
assertEquals(roleTreeNode.getId(), roleTreeNodeService.get(roleTreeNode.getId()).getId());
//
getHelper().deleteRole(role.getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndRemoveAutomaticRoleOnInvalidContract.
@Test
public void testSkipAndRemoveAutomaticRoleOnInvalidContract() {
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, node);
// role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getDirectRole() != null));
//
contract.setValidTill(LocalDate.now().minusDays(2));
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.UPDATE, contract);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
contract = service.publish(event).getContent();
UUID contractId = contract.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmIdentityContractDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(contractId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getDirectRole() != null));
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testAssignAutomaticRoleToExistIdentityAsync.
@Test
public void testAssignAutomaticRoleToExistIdentityAsync() {
IdmIdentityDto identityOne = getHelper().createIdentityOnly();
IdmIdentityDto identityTwo = getHelper().createIdentityOnly();
IdmIdentityDto identityThree = getHelper().createIdentityOnly();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityContractDto contractOne = getHelper().createContract(identityOne, treeNode);
IdmIdentityContractDto contractTwo = getHelper().createContract(identityTwo, treeNode);
IdmIdentityContractDto contractThree = getHelper().createContract(identityThree, treeNode);
IdmRoleDto role = getHelper().createRole();
//
List<IdmLongRunningTaskDto> lrts = null;
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
try {
IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
//
getHelper().waitForResult(res -> {
return identityRoleService.findByAutomaticRole(automaticRole.getId(), null).getTotalElements() != 3;
}, 500, 30);
getHelper().waitForResult(res -> {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setRunning(Boolean.TRUE);
//
return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
});
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findByAutomaticRole(automaticRole.getId(), null).getContent();
Assert.assertEquals(3, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractOne.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractTwo.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getIdentityContract().equals(contractThree.getId())));
//
// check asynchronous LRT
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setTransactionId(assignedRoles.get(0).getTransactionId());
lrts = taskManager.findLongRunningTasks(filter, null).getContent();
Assert.assertFalse(lrts.isEmpty());
Assert.assertTrue(lrts.stream().allMatch(lrt -> lrt.getResultState() == OperationState.EXECUTED));
//
// and check lrt start event is properly created and ended
IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
eventFilter.setOwnerType(entityEventManager.getOwnerType(IdmLongRunningTaskDto.class));
eventFilter.setTransactionId(assignedRoles.get(0).getTransactionId());
List<IdmEntityEventDto> events = entityEventManager.findEvents(eventFilter, null).getContent();
Assert.assertFalse(events.isEmpty());
Assert.assertTrue(events.stream().allMatch(event -> event.getResult().getState() == OperationState.EXECUTED));
Assert.assertTrue(events.stream().allMatch(event -> event.getEventStarted() != null));
Assert.assertTrue(events.stream().allMatch(event -> event.getEventEnded() != null));
Assert.assertTrue(events.stream().anyMatch(event -> event.getEventType().equals(LongRunningTaskEventType.START.name())));
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
//
if (lrts != null) {
lrts.forEach(lrt -> {
if (lrt.isRunning() || lrt.getResultState() == OperationState.RUNNING) {
taskManager.cancel(lrt.getId());
}
});
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testDontAssingRoleForInvalidContractWhenPositionIsChanged.
@Test
public void testDontAssingRoleForInvalidContractWhenPositionIsChanged() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmIdentityContractDto contractD = new IdmIdentityContractDto();
contractD.setIdentity(identity.getId());
contractD.setValidTill(LocalDate.now().minusDays(1));
contractD = service.save(contractD);
//
// create new automatic role
automaticRoleD = new IdmRoleTreeNodeDto();
automaticRoleD.setRecursionType(RecursionType.NO);
automaticRoleD.setRole(roleA.getId());
automaticRoleD.setTreeNode(nodeD.getId());
automaticRoleD = saveAutomaticRole(automaticRoleD, true);
//
contractD.setWorkPosition(nodeD.getId());
contractD = service.save(contractD);
//
// check
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contractD.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testDontRemoveSameRole.
@Test
public void testDontRemoveSameRole() {
automaticRoleF = new IdmRoleTreeNodeDto();
automaticRoleF.setRecursionType(RecursionType.UP);
automaticRoleF.setRole(roleA.getId());
automaticRoleF.setTreeNode(nodeF.getId());
automaticRoleF = saveAutomaticRole(automaticRoleF, false);
//
automaticRoleE = new IdmRoleTreeNodeDto();
automaticRoleE.setRecursionType(RecursionType.NO);
automaticRoleE.setRole(roleA.getId());
automaticRoleE.setTreeNode(nodeE.getId());
automaticRoleE = saveAutomaticRole(automaticRoleE, false);
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setWorkPosition(nodeF.getId());
contract = service.save(contract);
//
// check assigned role after creation
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(1, identityRoles.size());
assertEquals(roleA.getId(), identityRoles.get(0).getRole());
assertEquals(automaticRoleF.getId(), identityRoles.get(0).getAutomaticRole());
//
UUID id = identityRoles.get(0).getId();
//
// change
contract.setWorkPosition(nodeE.getId());
contract = service.save(contract);
//
// check assigned role after creation
identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(1, identityRoles.size());
assertEquals(roleA.getId(), identityRoles.get(0).getRole());
assertEquals(automaticRoleE.getId(), identityRoles.get(0).getAutomaticRole());
assertEquals(id, identityRoles.get(0).getId());
}
Aggregations