use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method addRoleWithSubprocessDisapproveTest.
@Test
public void addRoleWithSubprocessDisapproveTest() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
getHelper().waitForResult(null, 1, 1);
loginAsAdmin();
IdmIdentityDto test1 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
IdmIdentityDto test2 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
// Guarantee
int priority = 500;
IdmRoleDto role = getHelper().createRole();
role.setPriority(priority);
getHelper().createRoleGuarantee(role, test2);
role = roleService.save(role);
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_GUARANTEE_KEY);
IdmIdentityContractDto contract = getHelper().getPrimeContract(test1.getId());
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(role, contract, request);
concept = conceptRoleRequestService.save(concept);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCreatedAfter(now);
taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
// HELPDESK - must be skipped
// MANAGER
loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
// USER MANAGER
loginAsAdmin();
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
// Subprocess - approve by GUARANTEE
loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "disapprove");
// SECURITY
request = roleRequestService.get(request.getId());
loginAsAdmin();
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.EXECUTED, request.getState());
assertNotNull(request.getWfProcessId());
concept = conceptRoleRequestService.get(concept.getId());
assertNotNull(concept.getWfProcessId());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(test1.getId());
Page<IdmIdentityRoleDto> page = identityRoleService.find(filter, null);
assertEquals(0, page.getTotalElements());
Assert.assertTrue(identityRoleService.findAllByContract(contract.getId()).isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method addSuperAdminRoleWithSubprocessRemoveTest.
@Test
public void addSuperAdminRoleWithSubprocessRemoveTest() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
getHelper().waitForResult(null, 1, 1);
IdmIdentityDto test1 = getHelper().createIdentity("TestUser" + System.currentTimeMillis());
IdmIdentityDto test2 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
IdmIdentityContractDto contract = getHelper().getPrimeContract(test1.getId());
IdmRoleDto adminRole = getHelper().createRole();
adminRole.setApproveRemove(true);
roleService.save(adminRole);
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, contract, request);
concept = conceptRoleRequestService.save(concept);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCreatedAfter(now);
taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
loginAsAdmin();
// HELPDESK
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
// MANAGER
loginAsAdmin();
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
// USER MANAGER
loginAsAdmin();
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
// SECURITY
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.EXECUTED, request.getState());
assertNotNull(request.getWfProcessId());
concept = conceptRoleRequestService.get(concept.getId());
assertNotNull(concept.getWfProcessId());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(test1.getId());
Page<IdmIdentityRoleDto> page = identityRoleService.find(filter, null);
assertEquals(1, page.getContent().size());
loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
// Guarantee
int priority = 500;
adminRole.setPriority(priority);
getHelper().createRoleGuarantee(adminRole, test2);
adminRole = roleService.save(adminRole);
configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + (priority + priority), APPROVE_REMOVE_ROLE_BY_MANAGER_KEY);
IdmRoleRequestDto requestRemove = createRoleRequest(test1);
requestRemove = roleRequestService.save(requestRemove);
// Mock set of validity - only for test if created remove concept doesn't have filled validity
contract.setValidFrom(LocalDate.now());
contract.setValidTill(LocalDate.now());
IdmConceptRoleRequestDto conceptRemove = createRoleRemoveConcept(page.getContent().get(0).getId(), adminRole, contract, requestRemove);
conceptRemove = conceptRoleRequestService.save(conceptRemove);
// Remove concept should have not set a validity.
assertNull(conceptRemove.getValidFrom());
assertNull(conceptRemove.getValidTill());
roleRequestService.startRequestInternal(requestRemove.getId(), true);
requestRemove = roleRequestService.get(requestRemove.getId());
assertEquals(RoleRequestState.IN_PROGRESS, requestRemove.getState());
WorkflowFilterDto taskRemoveFilter = new WorkflowFilterDto();
taskRemoveFilter.setCreatedAfter(now);
// HELPDESK
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin();
taskRemoveFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// MANAGER
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin();
taskRemoveFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// USER MANAGER
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin();
taskRemoveFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// Subprocess - approve by GUARANTEE
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin();
taskRemoveFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
// SECURITY
requestRemove = roleRequestService.get(requestRemove.getId());
loginAsAdmin();
taskRemoveFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
requestRemove = roleRequestService.get(requestRemove.getId());
assertEquals(RoleRequestState.EXECUTED, requestRemove.getState());
assertNotNull(requestRemove.getWfProcessId());
conceptRemove = conceptRoleRequestService.get(conceptRemove.getId());
assertNotNull(conceptRemove.getWfProcessId());
IdmIdentityRoleFilter filterRemove = new IdmIdentityRoleFilter();
filterRemove.setIdentityId(test1.getId());
Page<IdmIdentityRoleDto> pageRemove = identityRoleService.find(filterRemove, null);
assertEquals(0, pageRemove.getContent().size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method cancelSubprocessOnRoleDeleteTest.
@Test
public void cancelSubprocessOnRoleDeleteTest() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
getHelper().waitForResult(null, 1, 1);
configurationService.setValue(APPROVE_BY_SECURITY_ENABLE, "false");
loginAsAdmin();
IdmIdentityDto test1 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
IdmIdentityDto test2 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
// Guarantee
int priority = 500;
IdmRoleDto adminRole = roleConfiguration.getAdminRole();
adminRole.setPriority(priority);
getHelper().createRoleGuarantee(adminRole, test2);
adminRole = roleService.save(adminRole);
configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_MANAGER_KEY);
IdmIdentityContractDto contract = getHelper().getPrimeContract(test1.getId());
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, contract, request);
concept = conceptRoleRequestService.save(concept);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCreatedAfter(now);
taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
// HELPDESK - must be skipped
// MANAGER
loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
// USER MANAGER
loginAsAdmin();
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
// Subprocess - approve by Manager
request = roleRequestService.get(request.getId());
loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
concept = conceptRoleRequestService.get(concept.getId());
String conceptWf = concept.getWfProcessId();
assertNotNull(conceptWf);
assertNotNull(workflowProcessInstanceService.get(conceptWf));
// Delete the role that is using in the concept
UUID roleId = concept.getRole();
assertNotNull(roleId);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleId);
identityRoleService.find(identityRoleFilter, null).getContent().forEach(identityRole -> identityRoleService.delete(identityRole));
// Wf process for concept cannot be cancelled (because main process would be frozen ). Process will be disapproved.
roleService.deleteById(roleId);
// Concept has to be in the Cancel state and WF must be ended
concept = conceptRoleRequestService.get(concept.getId());
assertEquals(RoleRequestState.CANCELED, concept.getState());
assertNotNull(concept.getWfProcessId());
assertNull(workflowProcessInstanceService.get(conceptWf));
request = roleRequestService.get(request.getId());
// Main process has to be executed
assertEquals(RoleRequestState.EXECUTED, request.getState());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityAccountManagementTest method defaultAccountRemove.
@Test
public void defaultAccountRemove() {
TestResource createdAccount = helper.findResource("x" + IDENTITY_USERNAME);
Assert.assertNotNull("Idenitity have to exists on target system (before account will be delete)", createdAccount);
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid("x" + IDENTITY_USERNAME);
Assert.assertEquals("Account needs to exist befor will be delete", 1, accountService.find(accountFilter, null).getContent().size());
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
IdmIdentityRoleFilter irfilter = new IdmIdentityRoleFilter();
irfilter.setIdentityId(identity.getId());
IdmIdentityRoleDto identityRoleToDelete = identityRoleService.find(irfilter, null).getContent().get(0);
// This evokes IdentityRole DELETE event. On this event will be start
// account management and provisioning
identityRoleService.deleteById(identityRoleToDelete.getId());
Assert.assertEquals("Account must not be after was deleted", 0, accountService.find(accountFilter, null).getContent().size());
AccIdentityAccountFilter iaccFilter = new AccIdentityAccountFilter();
iaccFilter.setIdentityId(identity.getId());
Assert.assertEquals("Idenitity account have to not exists after account was deleted!", 0, identityAccountService.find(iaccFilter, null).getContent().size());
createdAccount = helper.findResource("x" + IDENTITY_USERNAME);
Assert.assertNull("Idenitity have to no exists on target system (after account was deleted)", createdAccount);
// Reset value
identity.setFirstName(IDENTITY_USERNAME);
identityService.save(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testAssignedRoles.
@Test
public void testAssignedRoles() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
SysSystemAttributeMappingDto attributeAssignedRoles = new SysSystemAttributeMappingDto();
attributeAssignedRoles.setUid(false);
attributeAssignedRoles.setEntityAttribute(true);
attributeAssignedRoles.setIdmPropertyName(IdentityProvisioningExecutor.ASSIGNED_ROLES_FIELD);
attributeAssignedRoles.setTransformToResourceScript("if(attributeValue == null) " + System.lineSeparator() + "{return null;}" + System.lineSeparator() + " String result = '';" + System.lineSeparator() + " for(Object assignedRole : attributeValue)" + System.lineSeparator() + " {result = result + (assignedRole.toString())};" + System.lineSeparator() + " return result;");
attributeAssignedRoles.setName(descriptionSchemaAttribute.getName());
attributeAssignedRoles.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeAssignedRoles.setSystemMapping(defaultMapping.getId());
schemaAttributeMappingService.save(attributeAssignedRoles);
IdmRoleDto roleWithSystem = helper.createRole();
IdmRoleDto roleWithOutSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
IdmIdentityDto identity = helper.createIdentity();
helper.createIdentityRole(identity, roleWithOutSystem, null, null);
helper.createIdentityRole(identity, roleWithSystem, null, null);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
String result = "";
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
identityRole.getEavs().clear();
identityRole.getEavs().add(formInstanceDto);
result = result + IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRole).toString();
}
assertEquals(result, valueOnResource);
}
Aggregations