Search in sources :

Example 41 with IdmIdentityRoleDto

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

the class ChangeIdentityPermissionTest method addSuperAdminRoleWithSubprocessRemoveTest.

@Test
@Transactional
public void addSuperAdminRoleWithSubprocessRemoveTest() {
    IdmIdentityDto test1 = helper.createIdentity("TestUser" + System.currentTimeMillis());
    IdmIdentityDto test2 = identityService.getByUsername(InitTestData.TEST_USER_2);
    loginAsAdmin(InitTestData.TEST_USER_2);
    IdmIdentityContractDto contract = identityContractService.getPrimeContract(test1.getId());
    IdmRoleDto adminRole = helper.createRole("testRole" + System.currentTimeMillis());
    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.setCandidateOrAssigned(securityService.getCurrentUsername());
    List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    assertEquals(0, tasks.size());
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    // HELPDESK
    taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
    // MANAGER
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
    // USER MANAGER
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskFilter, test1.getUsername(), "approve");
    // SECURITY
    taskFilter.setCandidateOrAssigned(InitTestData.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(InitTestData.TEST_USER_2);
    // Guarantee
    int priority = 500;
    adminRole.setPriority(priority);
    IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
    guarantee.setRole(adminRole.getId());
    guarantee.setGuarantee(test2.getId());
    adminRole.getGuarantees().add(guarantee);
    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);
    IdmConceptRoleRequestDto conceptRemove = createRoleRemoveConcept(page.getContent().get(0).getId(), adminRole, contract, requestRemove);
    conceptRemove = conceptRoleRequestService.save(conceptRemove);
    roleRequestService.startRequestInternal(requestRemove.getId(), true);
    requestRemove = roleRequestService.get(requestRemove.getId());
    assertEquals(RoleRequestState.IN_PROGRESS, requestRemove.getState());
    WorkflowFilterDto taskRemoveFilter = new WorkflowFilterDto();
    // HELPDESK
    requestRemove = roleRequestService.get(requestRemove.getId());
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
    // MANAGER
    requestRemove = roleRequestService.get(requestRemove.getId());
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
    // USER MANAGER
    requestRemove = roleRequestService.get(requestRemove.getId());
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
    // Subprocess - approve by GUARANTEE
    requestRemove = roleRequestService.get(requestRemove.getId());
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskRemoveFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskRemoveFilter, test1.getUsername(), "approve");
    // SECURITY
    requestRemove = roleRequestService.get(requestRemove.getId());
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskRemoveFilter.setCandidateOrAssigned(InitTestData.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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) 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)

Example 42 with IdmIdentityRoleDto

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

the class DefaultIdentityRoleServiceTest method roleCatalogueTest.

@Test
public void roleCatalogueTest() {
    IdmIdentityDto person = testHelper.createIdentity();
    IdmIdentityDto person2 = testHelper.createIdentity();
    IdmRoleCatalogueDto catalogue = testHelper.createRoleCatalogue();
    IdmRoleCatalogueRoleDto catalogueRole = new IdmRoleCatalogueRoleDto();
    IdmRoleCatalogueRoleDto catalogueRole2 = new IdmRoleCatalogueRoleDto();
    IdmIdentityContractDto contract = testHelper.createIdentityContact(person);
    IdmIdentityContractDto contract2 = testHelper.createIdentityContact(person2);
    IdmRoleDto role = testHelper.createRole();
    IdmRoleDto role2 = testHelper.createRole();
    catalogueRole.setRoleCatalogue(catalogue.getId());
    catalogueRole.setRole(role.getId());
    catalogueRole2.setRoleCatalogue(catalogue.getId());
    catalogueRole2.setRole(role2.getId());
    IdmIdentityRoleDto roleCover = testHelper.createIdentityRole(contract, role);
    IdmIdentityRoleDto roleCover2 = testHelper.createIdentityRole(contract2, role2);
    idmRoleCatalogueRoleService.save(catalogueRole);
    idmRoleCatalogueRoleService.save(catalogueRole2);
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setRoleCatalogueId(catalogue.getId());
    Page<IdmIdentityRoleDto> result = idmIdentityRoleService.find(filter, null);
    assertEquals("Wrong CatalogueRoleId", roleCover.getId(), result.getContent().get(0).getId());
    assertEquals("Wrong CatalogueRoleId2", roleCover2.getId(), result.getContent().get(1).getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleCatalogueRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueRoleDto) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 43 with IdmIdentityRoleDto

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

the class DefaultIdentityRoleServiceTest method identityIdTest.

@Test
public void identityIdTest() {
    IdmRoleDto role = testHelper.createRole();
    IdmIdentityDto person = testHelper.createIdentity();
    IdmIdentityRoleDto addRole = testHelper.createIdentityRole(person, role);
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(person.getId());
    Page<IdmIdentityRoleDto> result = idmIdentityRoleService.find(filter, null);
    assertEquals("Wrong RoleId", addRole.getId(), result.getContent().get(0).getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 44 with IdmIdentityRoleDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithoutCheck.

@Test
public void testRemoveLastRuleWithoutCheck() {
    String eavCode = "testingEav";
    Long testEavIdentityValue = System.currentTimeMillis();
    UUID testEavContractValue = UUID.randomUUID();
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmRoleDto role = testHelper.createRole();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    // create two eav attributes (for identity and contract)
    IdmFormAttributeDto eavAttributeIdentity = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.LONG);
    testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.LONG);
    IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.UUID);
    testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.UUID);
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    IdmAutomaticRoleAttributeRuleDto rule1 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
    IdmAutomaticRoleAttributeRuleDto rule2 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    automaticRoleAttributeRuleService.delete(rule1);
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    automaticRoleAttributeRuleService.delete(rule2);
    // in this case we not able remove the last automatic role from identity
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 45 with IdmIdentityRoleDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testEmptyContract.

@Test
public void testEmptyContract() {
    String testValue = "123!@#" + System.currentTimeMillis();
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, testValue);
    // 
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    // remove contract
    IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
    identityContractService.delete(primeContract);
    primeContract = identityContractService.getPrimeContract(identity.getId());
    assertNull(primeContract);
    // 
    identity.setDescription(testValue);
    identity = identityService.save(identity);
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // change value and recalculate
    identity.setDescription(testValue + "-test");
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // chnage back
    identity.setDescription(testValue);
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)122 Test (org.junit.Test)94 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)90 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)72 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)71 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)54 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)30 LocalDate (org.joda.time.LocalDate)21 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)19 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)16 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)15 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)13 UUID (java.util.UUID)13 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)11 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)10 Transactional (org.springframework.transaction.annotation.Transactional)10 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)9 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)8 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7