use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testAssignRemove.
@Test
@Transactional
public void testAssignRemove() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
this.getHelper().createIdentityRole(contract, role);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
// Create request for remove identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setIdentityRole(identityRoles.get(0).getId());
dto.setId(dto.getIdentityRole());
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.deleteRequestIdentityRole(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(1, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
Assert.assertEquals(contract.getId(), concept.getIdentityContract());
Assert.assertEquals(role.getId(), concept.getRole());
Assert.assertEquals(ConceptRoleRequestOperation.REMOVE, concept.getOperation());
this.getHelper().executeRequest(request, false, true);
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testAssignRoles.
@Test
@Transactional
public void testAssignRoles() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
IdmRoleDto roleTwo = this.getHelper().createRole();
IdmRoleDto roleThree = this.getHelper().createRole();
Set<UUID> roles = Sets.newSet(role.getId(), roleTwo.getId(), roleThree.getId());
// Create request for new identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setRole(role.getId());
dto.setRoles(Sets.newSet(roleTwo.getId(), roleThree.getId()));
dto.setValidFrom(LocalDate.now().minusDays(1));
dto.setValidTill(LocalDate.now().plusDays(10));
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest());
Assert.assertNotNull(request);
// Concepts are empty, because the request does not return them be default
Assert.assertEquals(0, request.getConceptRoles().size());
request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(3, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
request.getConceptRoles().forEach(concept -> {
Assert.assertEquals(contract.getId(), concept.getIdentityContract());
Assert.assertTrue(roles.contains(concept.getRole()));
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
});
this.getHelper().executeRequest(request, false, true);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(3, identityRoles.size());
identityRoles.forEach(identityRole -> {
Assert.assertTrue(roles.contains(identityRole.getRole()));
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), identityRole.getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), identityRole.getValidTill());
});
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testUpdateAddingConcept.
@Test
@Transactional
public void testUpdateAddingConcept() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
// Create request for new identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setRole(role.getId());
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
// We want to update created concept -> update validity
createdRequestIdentityRole.setValidFrom(LocalDate.now().minusDays(1));
createdRequestIdentityRole.setValidTill(LocalDate.now().plusDays(10));
createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(1, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
Assert.assertEquals(contract.getId(), concept.getIdentityContract());
Assert.assertEquals(role.getId(), concept.getRole());
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
Assert.assertEquals(ConceptRoleRequestOperation.ADD, concept.getOperation());
this.getHelper().executeRequest(request, false, true);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(role.getId(), identityRoles.get(0).getRole());
Assert.assertEquals(LocalDate.now().minusDays(1), identityRoles.get(0).getValidFrom());
Assert.assertEquals(LocalDate.now().plusDays(10), identityRoles.get(0).getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testFind.
@Test
@Transactional
public void testFind() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto assignedRole = this.getHelper().createRole();
IdmIdentityRoleDto identityRole = this.getHelper().createIdentityRole(contract, assignedRole);
IdmRoleDto role = this.getHelper().createRole();
IdmRequestIdentityRoleFilter filter = new IdmRequestIdentityRoleFilter();
filter.setIdentityId(identity.getId());
// We expecting only one already assigned identity-role
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, requestIdentityRoles.size());
Assert.assertEquals(identityRole.getId(), requestIdentityRoles.get(0).getId());
// Create request for new identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setRole(role.getId());
dto.setValidFrom(LocalDate.now().minusDays(1));
dto.setValidTill(LocalDate.now().plusDays(10));
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
// Filter will be filtering by this request
filter.setRoleRequestId(createdRequestIdentityRole.getRoleRequest());
// We expecting two items, one assigned identity-role and one adding concept
requestIdentityRoles = requestIdentityRoleService.find(filter, null).getContent();
Assert.assertEquals(2, requestIdentityRoles.size());
IdmRequestIdentityRoleDto addingConcept = requestIdentityRoles.stream().filter(requestIdentityRole -> ConceptRoleRequestOperation.ADD == requestIdentityRole.getOperation()).findFirst().orElse(null);
Assert.assertNotNull(addingConcept);
Assert.assertEquals(createdRequestIdentityRole.getRoleRequest(), addingConcept.getRoleRequest());
Assert.assertEquals(role.getId(), addingConcept.getRole());
Assert.assertEquals(dto.getValidFrom(), addingConcept.getValidFrom());
Assert.assertEquals(dto.getValidTill(), addingConcept.getValidTill());
// Create request for remove identity-role
IdmRequestIdentityRoleDto dtoForRemove = new IdmRequestIdentityRoleDto();
dtoForRemove.setRoleRequest(createdRequestIdentityRole.getRoleRequest());
dtoForRemove.setIdentityRole(identityRole.getId());
dtoForRemove.setId(identityRole.getId());
// Remove existing identity-role -> new removing concept
IdmRequestIdentityRoleDto deleteRequestIdentityRole = requestIdentityRoleService.deleteRequestIdentityRole(dtoForRemove);
Assert.assertEquals(createdRequestIdentityRole.getRoleRequest(), deleteRequestIdentityRole.getRoleRequest());
// We expecting two items, one adding concept and one removing concept
requestIdentityRoles = requestIdentityRoleService.find(filter, null).getContent();
Assert.assertEquals(2, requestIdentityRoles.size());
IdmRequestIdentityRoleDto removingConcept = requestIdentityRoles.stream().filter(requestIdentityRole -> ConceptRoleRequestOperation.REMOVE == requestIdentityRole.getOperation()).findFirst().orElse(null);
Assert.assertNotNull(removingConcept);
Assert.assertEquals(createdRequestIdentityRole.getRoleRequest(), removingConcept.getRoleRequest());
Assert.assertEquals(identityRole.getId(), removingConcept.getIdentityRole());
Assert.assertNotEquals(removingConcept.getId(), removingConcept.getIdentityRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterNodeIsMovedWithUpRecursion.
@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterNodeIsMovedWithUpRecursion() {
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().createContractPosition(getHelper().getPrimeContract(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();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmRoleTreeNodeDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
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())));
}
Aggregations