use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method changePermissionViaRoleRequestTest.
@Test
@Transactional
public void changePermissionViaRoleRequestTest() {
this.addPermissionViaRoleRequestTest();
IdmIdentityDto testA = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleA = getHelper().createRole(100);
IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
getHelper().createIdentityRole(testA, roleA);
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(testA.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request = roleRequestService.save(request);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(testA.getId());
Assert.assertEquals(1, identityRoles.size());
LocalDate validFrom = LocalDate.now().minusDays(1);
IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
conceptA.setRoleRequest(request.getId());
conceptA.setRole(identityRoles.get(0).getRole());
conceptA.setOperation(ConceptRoleRequestOperation.UPDATE);
conceptA.setValidFrom(validFrom);
conceptA.setValidTill(null);
conceptA.setIdentityContract(contractA.getId());
conceptA.setIdentityRole(identityRoles.get(0).getId());
conceptA = conceptRoleRequestService.save(conceptA);
getHelper().startRequestInternal(request, true, true);
request = roleRequestService.get(request.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, request.getState());
identityRoles = identityRoleService.findAllByIdentity(testA.getId());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(validFrom, identityRoles.get(0).getValidFrom());
Assert.assertEquals(null, identityRoles.get(0).getValidTill());
Assert.assertEquals(contractA.getId(), identityRoles.get(0).getIdentityContract());
Assert.assertEquals(roleA.getId(), identityRoles.get(0).getRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesByIdentity.
@Test
@Transactional
public void testCopyRolesByIdentity() {
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = this.getHelper().createRole();
IdmRoleDto roleTwo = this.getHelper().createRole();
IdmIdentityContractDto primeContract = this.getHelper().getPrimeContract(identityDto);
this.getHelper().createIdentityRole(primeContract, roleOne);
this.getHelper().createIdentityRole(primeContract, roleTwo);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identityDto.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityDto newIdentity = this.getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto newIdentityContract = this.getHelper().getPrimeContract(newIdentity);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(newIdentityContract);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(newIdentityContract.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setRoleRequest(createdRequest.getId());
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
assertNotNull(copyRolesByIdentity);
assertEquals(createdRequest.getId(), copyRolesByIdentity.getId());
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(2, concepts.size());
IdmConceptRoleRequestDto conceptOne = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleOne.getId());
}).findAny().orElse(null);
assertNotNull(conceptOne);
IdmConceptRoleRequestDto conceptTwo = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleTwo.getId());
}).findAny().orElse(null);
assertNotNull(conceptTwo);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testSkipAndAssignAutomaticRoleAfterNodeIsMovedWithUpRecursion.
@Test
public void testSkipAndAssignAutomaticRoleAfterNodeIsMovedWithUpRecursion() {
IdmTreeNodeDto parentNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.UP, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
getHelper().createContract(identity, parentNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
node.setParent(parentNode.getId());
EntityEvent<IdmTreeNodeDto> event = new TreeNodeEvent(TreeNodeEventType.UPDATE, node);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
node = service.publish(event).getContent();
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
//
IdmTreeNodeDto otherNode = getHelper().createTreeNode(null, null, node);
IdmRoleDto roleOther = getHelper().createRole();
IdmRoleTreeNodeDto otherAutomaticRole = getHelper().createRoleTreeNode(roleOther, otherNode, RecursionType.UP, false);
//
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 -> otherAutomaticRole.getId().equals(ir.getAutomaticRole())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testAssignAutomaticRoleAfterNodeIsMovedWithDownRecursion.
@Test
public void testAssignAutomaticRoleAfterNodeIsMovedWithDownRecursion() {
IdmTreeNodeDto parentNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, parentNode, RecursionType.DOWN, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
getHelper().createContract(identity, node);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
node.setParent(parentNode.getId());
node = service.save(node);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
//
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmRoleTreeNodeDto otherAutomaticRole = getHelper().createRoleTreeNode(role, otherNode, RecursionType.DOWN, true);
node.setParent(otherNode.getId());
node = service.save(node);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
UUID assignedRoleId = assignedRoles.get(0).getId();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(otherAutomaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
//
// recalculate role => nothing happend
ProcessAutomaticRoleByTreeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
automaticRoleTask.setAutomaticRoles(Lists.newArrayList(otherAutomaticRole.getId()));
longRunningTaskManager.execute(automaticRoleTask);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(otherAutomaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
Assert.assertEquals(assignedRoleId, assignedRoles.get(0).getId());
//
// move node deeper in sub tree => nothing should happend
IdmTreeNodeDto subNode = getHelper().createTreeNode(null, null, getHelper().createTreeNode(null, null, otherNode));
node.setParent(subNode.getId());
node = service.save(node);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(otherAutomaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
Assert.assertEquals(assignedRoleId, assignedRoles.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleValidRequestIntegrationTest method createAndSaveIdentityRole.
private IdmIdentityRoleDto createAndSaveIdentityRole(IdmIdentityContractDto identityContract, IdmRoleDto role, LocalDate validTill, LocalDate validFrom) {
IdmIdentityRoleDto entity = new IdmIdentityRoleDto();
entity.setValidTill(validTill);
entity.setValidFrom(validFrom);
entity.setRole(role.getId());
entity.setIdentityContract(identityContract.getId());
return saveInTransaction(entity, idmIdentityRoleSerivce);
}
Aggregations