Search in sources :

Example 1 with IdmRoleGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleGuaranteeServiceIntegrationTest method testFindRoleGuaranteeByRole.

@Test
public void testFindRoleGuaranteeByRole() {
    IdmIdentityDto guarantee1 = testHelper.createIdentity();
    IdmIdentityDto guarantee2 = testHelper.createIdentity();
    IdmIdentityDto guarantee3 = testHelper.createIdentity();
    // 
    IdmRoleDto role = testHelper.createRole();
    // 
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(guarantee1.getId());
    roleGuaranteeService.save(roleGuarantee);
    // 
    roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(guarantee2.getId());
    roleGuaranteeService.save(roleGuarantee);
    // 
    roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(guarantee3.getId());
    roleGuaranteeService.save(roleGuarantee);
    // 
    IdmRoleGuaranteeFilter filter = new IdmRoleGuaranteeFilter();
    filter.setRole(role.getId());
    List<IdmRoleGuaranteeDto> list = roleGuaranteeService.find(filter, null).getContent();
    assertEquals(3, list.size());
    // 
    List<UUID> guarantees = list.stream().map(IdmRoleGuaranteeDto::getGuarantee).collect(Collectors.toList());
    roleGuarantee = list.get(0);
    assertEquals(role.getId(), roleGuarantee.getRole());
    assertTrue(guarantees.contains(guarantee3.getId()));
    assertTrue(guarantees.contains(guarantee2.getId()));
    assertTrue(guarantees.contains(guarantee1.getId()));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 2 with IdmRoleGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleGuaranteeServiceIntegrationTest method testFindRoleGuaranteeByGuarantee.

@Test
public void testFindRoleGuaranteeByGuarantee() {
    IdmIdentityDto guarantee = testHelper.createIdentity();
    // 
    IdmRoleDto role1 = testHelper.createRole();
    IdmRoleDto role2 = testHelper.createRole();
    IdmRoleDto role3 = testHelper.createRole();
    // 
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role1.getId());
    roleGuarantee.setGuarantee(guarantee.getId());
    roleGuaranteeService.save(roleGuarantee);
    // 
    roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role2.getId());
    roleGuarantee.setGuarantee(guarantee.getId());
    roleGuaranteeService.save(roleGuarantee);
    // 
    roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role3.getId());
    roleGuarantee.setGuarantee(guarantee.getId());
    roleGuaranteeService.save(roleGuarantee);
    // 
    IdmRoleGuaranteeFilter filter = new IdmRoleGuaranteeFilter();
    filter.setGuarantee(guarantee.getId());
    List<IdmRoleGuaranteeDto> list = roleGuaranteeService.find(filter, null).getContent();
    assertEquals(3, list.size());
    // 
    List<UUID> roles = list.stream().map(IdmRoleGuaranteeDto::getRole).collect(Collectors.toList());
    roleGuarantee = list.get(0);
    assertEquals(guarantee.getId(), roleGuarantee.getGuarantee());
    assertTrue(roles.contains(role1.getId()));
    assertTrue(roles.contains(role2.getId()));
    assertTrue(roles.contains(role3.getId()));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 3 with IdmRoleGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleServiceIntegrationTest method testReferentialIntegrity.

@Test
public void testReferentialIntegrity() {
    IdmIdentityDto identity = new IdmIdentityDto();
    String username = "delete_test_" + System.currentTimeMillis();
    identity.setUsername(username);
    // confidential storage
    identity.setPassword(new GuardedString("heslo"));
    identity.setFirstName("Test");
    identity.setLastName("Identity");
    identity = identityService.save(identity);
    // role
    IdmRoleDto role = new IdmRoleDto();
    String roleName = "test_r_" + System.currentTimeMillis();
    role.setName(roleName);
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(identity.getId());
    role.setGuarantees(Lists.newArrayList(roleGuarantee));
    role = roleService.save(role);
    assertNotNull(roleService.getByCode(roleName));
    assertEquals(1, roleGuaranteeRepository.findAllByRole_Id(role.getId()).size());
    roleService.delete(role);
    assertNull(roleService.getByCode(roleName));
    assertEquals(0, roleGuaranteeRepository.findAllByRole_Id(role.getId()).size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with IdmRoleGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleServiceIntegrationTest method guaranteeFilterTest.

@Test
public void guaranteeFilterTest() {
    IdmIdentityDto identity = helper.createIdentity();
    IdmRoleDto role = new IdmRoleDto();
    role.setName("IgnacMikinaRole");
    helper.createRole();
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(identity.getId());
    role.setGuarantees(Lists.newArrayList(roleGuarantee));
    role = roleService.save(role);
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setGuaranteeId(identity.getId());
    Page<IdmRoleDto> result = roleService.find(filter, null);
    assertEquals("Wrong guarantee", 1, result.getTotalElements());
    assertEquals("Wrong guarantee id", role.getId(), result.getContent().get(0).getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with IdmRoleGuaranteeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto in project CzechIdMng by bcvsolutions.

the class ChangeIdentityPermissionTest method testTaskCount.

@Test
@Transactional
public void testTaskCount() {
    configurationService.setValue(APPROVE_BY_SECURITY_ENABLE, "false");
    configurationService.setValue(APPROVE_BY_MANAGER_ENABLE, "false");
    configurationService.setValue(APPROVE_BY_HELPDESK_ENABLE, "true");
    configurationService.setValue(APPROVE_BY_USERMANAGER_ENABLE, "false");
    // 
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    IdmIdentityDto test1 = helper.createIdentity();
    IdmIdentityDto guarantee = helper.createIdentity();
    // Guarantee
    int priority = 500;
    IdmRoleDto role = helper.createRole();
    role.setPriority(priority);
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(guarantee.getId());
    role.getGuarantees().add(roleGuarantee);
    role = roleService.save(role);
    // set approve by guarantee
    configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_GUARANTEE_KEY);
    // helpdesk role and identity
    IdmRoleDto helpdeskRole = helper.createRole();
    IdmIdentityDto helpdeskIdentity = helper.createIdentity();
    // add role directly
    helper.createIdentityRole(helpdeskIdentity, helpdeskRole);
    configurationService.setValue(APPROVE_BY_HELPDESK_ROLE, helpdeskRole.getCode());
    IdmIdentityContractDto contract = helper.getPrimeContract(test1.getId());
    // check task before create request
    loginAsAdmin(test1.getUsername());
    int taskCount = getHistoricProcess().size();
    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.setCandidateOrAssigned(securityService.getCurrentUsername());
    List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    assertEquals(0, tasks.size());
    // check tasks after create request, must be +1
    loginAsAdmin(test1.getUsername());
    int taksCountAfter = getHistoricProcess().size();
    assertEquals(taskCount + 1, taksCountAfter);
    // HELPDESK
    loginAsAdmin(helpdeskIdentity.getUsername());
    taskFilter.setCandidateOrAssigned(helpdeskIdentity.getUsername());
    checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
    // check tasks by identity, must be + 2 (main process + sub process)
    loginAsAdmin(test1.getUsername());
    taksCountAfter = getHistoricProcess().size();
    assertEquals(taskCount + 2, taksCountAfter);
    // Subprocess - approve by GUARANTEE
    loginAsAdmin(guarantee.getUsername());
    taskFilter.setCandidateOrAssigned(guarantee.getUsername());
    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());
    // check task on the end (same as before)
    loginAsAdmin(test1.getUsername());
    taksCountAfter = getHistoricProcess().size();
    assertEquals(taskCount + 2, taksCountAfter);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)18 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)18 Test (org.junit.Test)18 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)13 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)7 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)7 UUID (java.util.UUID)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)6 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)6 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)6 Transactional (org.springframework.transaction.annotation.Transactional)6 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)5 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)3 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)3 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)3