Search in sources :

Example 21 with IdmIncompatibleRoleDto

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

the class DefaultIdmIncompatibleRoleServiceIntegrationTest method testResolveIncompatibleRolesInBulkRequest.

@Test
public void testResolveIncompatibleRolesInBulkRequest() {
    IdmRoleDto superior = getHelper().createRole();
    IdmRoleDto superiorTwo = getHelper().createRole();
    IdmRoleDto subOne = getHelper().createRole();
    IdmRoleDto subTwo = getHelper().createRole();
    IdmRoleDto subOneSub = getHelper().createRole();
    IdmRoleDto subOneSubSub = getHelper().createRole();
    IdmRoleDto three = getHelper().createRole();
    IdmRoleDto threeSub = getHelper().createRole();
    IdmRoleDto threeSubSub = getHelper().createRole();
    getHelper().createRoleComposition(superior, subOne);
    getHelper().createRoleComposition(superior, subTwo);
    getHelper().createRoleComposition(subOne, subOneSub);
    getHelper().createRoleComposition(subOneSub, subOneSubSub);
    getHelper().createRoleComposition(three, threeSub);
    getHelper().createRoleComposition(threeSub, threeSubSub);
    // prepare incompatible roles
    getHelper().createIncompatibleRole(subOne, subTwo);
    getHelper().createIncompatibleRole(subOneSubSub, threeSubSub);
    getHelper().createIncompatibleRole(subTwo, threeSub);
    getHelper().createIncompatibleRole(subOne, subOne);
    // create superior roles
    List<IdmRoleDto> assignRoles = Lists.newArrayList(three, superior, superiorTwo);
    // 
    // *5 => 1000
    int count = 200;
    for (int i = 1; i <= count; i++) {
        IdmRoleDto role = getHelper().createRole();
        // create some sub roles
        IdmRoleDto subRole = getHelper().createRole();
        IdmRoleDto subSubRoleOne = getHelper().createRole();
        IdmRoleDto subSubRoleTwo = getHelper().createRole();
        IdmRoleDto subSubRoleThree = getHelper().createRole();
        getHelper().createRoleComposition(role, subRole);
        getHelper().createRoleComposition(subRole, subSubRoleOne);
        getHelper().createRoleComposition(subRole, subSubRoleTwo);
        getHelper().createRoleComposition(subRole, subSubRoleThree);
        getHelper().createIncompatibleRole(threeSubSub, subSubRoleOne);
        // 
        // assign target system - should exist
        // FIXME: move to some new acc test, just backup here ...
        // SysSystemDto system = systemService.getByCode("manual-vs");
        // SysSystemMappingDto systemMapping =  AutowireHelper.getBean(SysSystemMappingService.class).findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
        // SysRoleSystemDto roleSystem = new SysRoleSystemDto();
        // roleSystem.setSystem(system.getId());
        // roleSystem.setSystemMapping(systemMapping.getId());
        // roleSystem.setRole(role.getId());
        // //
        // // merge attribute - rights + transformation
        // AutowireHelper.getBean(SysRoleSystemAttributeService.class).addRoleMappingAttribute(system.getId(),
        // role.getId(), "rights", "return [\"value-" + i +"\"]", IcObjectClassInfo.ACCOUNT);
        assignRoles.add(role);
    }
    // 
    // prepare owner
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    // 
    // prepare request
    IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
    roleRequest.setState(RoleRequestState.CONCEPT);
    // without approval
    roleRequest.setExecuteImmediately(true);
    roleRequest.setApplicant(identity.getId());
    roleRequest.setRequestedByType(RoleRequestedByType.MANUALLY);
    roleRequest = getHelper().getService(IdmRoleRequestService.class).save(roleRequest);
    // 
    for (IdmRoleDto assignRole : assignRoles) {
        IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
        concept.setIdentityContract(contract.getId());
        concept.setValidFrom(contract.getValidFrom());
        concept.setValidTill(contract.getValidTill());
        concept.setRole(assignRole.getId());
        concept.setOperation(ConceptRoleRequestOperation.ADD);
        concept.setRoleRequest(roleRequest.getId());
        // 
        getHelper().getService(IdmConceptRoleRequestService.class).save(concept);
    }
    long start = System.currentTimeMillis();
    // 
    Set<IdmIncompatibleRoleDto> incompatibleRoles = getHelper().getService(IdmRoleRequestService.class).getIncompatibleRoles(roleRequest).stream().map(ResolvedIncompatibleRoleDto::getIncompatibleRole).collect(Collectors.toSet());
    // 
    long duration = System.currentTimeMillis() - start;
    Assert.assertTrue(duration < 30000);
    Assert.assertEquals(3 + count, incompatibleRoles.size());
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(subOneSubSub.getId()) && ir.getSub().equals(threeSubSub.getId());
    }));
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(subOne.getId()) && ir.getSub().equals(subTwo.getId());
    }));
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(subTwo.getId()) && ir.getSub().equals(threeSub.getId());
    }));
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(threeSubSub.getId());
    }));
}
Also used : IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) Autowired(org.springframework.beans.factory.annotation.Autowired) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) Lists(com.google.common.collect.Lists) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) Serializable(java.io.Serializable) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIncompatibleRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto)21 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)16 Test (org.junit.Test)15 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 List (java.util.List)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 ResolvedIncompatibleRoleDto (eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto)10 Assert (org.junit.Assert)10 Set (java.util.Set)9 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)7 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)7 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 Collectors (java.util.stream.Collectors)7 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)6 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)6 Lists (com.google.common.collect.Lists)5 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)4