Search in sources :

Example 21 with IdmIdentityRoleFilter

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

the class ProcessAllAutomaticRoleByAttributeTaskExecutor method processAutomaticRoleForContract.

/**
 * Start recalculation for automatic role. All identity roles (newly added and removed) will be added by {@link IdmRoleRequestDto}.
 * But role request is created for each contract twice. One for newly added and one for newly removed. This is now only solutions.
 *
 * @param automaticRolAttributeDto
 */
private void processAutomaticRoleForContract(IdmAutomaticRoleAttributeDto automaticRolAttributeDto) {
    UUID automaticRoleId = automaticRolAttributeDto.getId();
    // 
    // process contracts
    List<UUID> newPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, true, null).getContent();
    List<UUID> newNotPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, false, null).getContent();
    // 
    boolean canContinue = true;
    for (UUID contractId : newPassedContracts) {
        // Concepts that will be added
        List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
        // 
        IdmIdentityContractDto contract = identityContractService.get(contractId);
        // 
        IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
        concept.setIdentityContract(contract.getId());
        concept.setValidFrom(contract.getValidFrom());
        concept.setValidTill(contract.getValidTill());
        concept.setRole(automaticRolAttributeDto.getRole());
        concept.setAutomaticRole(automaticRoleId);
        concept.setOperation(ConceptRoleRequestOperation.ADD);
        concepts.add(concept);
        IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
        roleRequest.setConceptRoles(concepts);
        roleRequest.setApplicant(contract.getIdentity());
        roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
        canContinue = updateState();
        if (!canContinue) {
            break;
        }
    }
    // 
    if (canContinue) {
        for (UUID contractId : newNotPassedContracts) {
            // Identity id is get from embedded identity role. This is little speedup.
            UUID identityId = null;
            // 
            IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
            filter.setIdentityContractId(contractId);
            filter.setAutomaticRoleId(automaticRoleId);
            List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
            // Concepts that will be added
            List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(identityRoles.size());
            for (IdmIdentityRoleDto identityRole : identityRoles) {
                IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
                concept.setIdentityContract(contractId);
                concept.setRole(automaticRolAttributeDto.getRole());
                concept.setAutomaticRole(automaticRoleId);
                concept.setIdentityRole(identityRole.getId());
                concept.setOperation(ConceptRoleRequestOperation.REMOVE);
                concepts.add(concept);
                if (identityId == null) {
                    IdmIdentityContractDto contractDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract, IdmIdentityContractDto.class, null);
                    identityId = contractDto.getIdentity();
                }
            }
            IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
            roleRequest.setConceptRoles(concepts);
            roleRequest.setApplicant(identityId);
            roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
            canContinue = updateState();
            if (!canContinue) {
                break;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) UUID(java.util.UUID) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 22 with IdmIdentityRoleFilter

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

the class ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor method removeAllAutomaticRoles.

private void removeAllAutomaticRoles(IdmIdentityContractDto invalidContract) {
    UUID contractId = invalidContract.getId();
    UUID identityId = invalidContract.getIdentity();
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityContractId(contractId);
    filter.setAutomaticRole(Boolean.TRUE);
    filter.setDirectRole(Boolean.TRUE);
    // 
    List<IdmIdentityRoleDto> contractRoles = identityRoleService.find(filter, null).getContent();
    List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(contractRoles.size());
    for (IdmIdentityRoleDto identityRole : contractRoles) {
        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
        conceptRoleRequest.setIdentityRole(identityRole.getId());
        conceptRoleRequest.setAutomaticRole(identityRole.getAutomaticRole());
        conceptRoleRequest.setRole(identityRole.getRole());
        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
        conceptRoleRequest.setIdentityContract(contractId);
        // 
        concepts.add(conceptRoleRequest);
    }
    if (concepts.isEmpty()) {
        LOG.debug("invalid contract [{}] does not have assigned roles.", contractId);
        // 
        return;
    }
    IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
    roleRequest.setState(RoleRequestState.CONCEPT);
    // without approval
    roleRequest.setExecuteImmediately(true);
    roleRequest.setApplicant(identityId);
    roleRequest.setRequestedByType(RoleRequestedByType.AUTOMATICALLY);
    roleRequest = roleRequestService.save(roleRequest);
    // 
    for (IdmConceptRoleRequestDto concept : concepts) {
        concept.setRoleRequest(roleRequest.getId());
        // 
        conceptRoleRequestService.save(concept);
    }
    // 
    // start event with skip check authorities
    RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
    requestEvent.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
    // prevent to start asynchronous event before previous update event is completed.
    requestEvent.setSuperOwnerId(identityId);
    // 
    roleRequestService.startRequestInternal(requestEvent);
}
Also used : ArrayList(java.util.ArrayList) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) UUID(java.util.UUID) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 23 with IdmIdentityRoleFilter

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

the class DefaultIdmContractPositionServiceIntegrationTest method testAssignSameAutomaticRoleAsContract.

@Test
public void testAssignSameAutomaticRoleAsContract() {
    // create automatic role on tree node
    IdmRoleDto role = getHelper().createRole();
    IdmTreeNodeDto node = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRoleTwo = getHelper().createAutomaticRole(role, node);
    // create identity
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().createContract(identity, node);
    getHelper().createContractPosition(contract, node);
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertEquals(2, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().allMatch(ir -> ir.getAutomaticRole().equals(automaticRoleTwo.getId())));
}
Also used : Lists(org.testng.collections.Lists) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) ApplicationContext(org.springframework.context.ApplicationContext) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 24 with IdmIdentityRoleFilter

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

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRecalculationWithManyIdentitiesProcessAll.

@Test
public void testRecalculationWithManyIdentitiesProcessAll() {
    String description = getHelper().createName();
    List<IdmIdentityDto> identities = new ArrayList<IdmIdentityDto>();
    try {
        for (int index = 0; index < 241; index++) {
            IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
            identity.setDescription(description);
            identityService.save(identity);
            identities.add(identity);
        }
        assertEquals(241, identities.size());
        IdmRoleDto role = getHelper().createRole();
        IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
        getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, description);
        ProcessAllAutomaticRoleByAttributeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAllAutomaticRoleByAttributeTaskExecutor.class);
        longRunningTaskManager.executeSync(automaticRoleTask);
        IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
        filter.setAutomaticRoleId(automaticRole.getId());
        List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
        assertEquals(241, identityRoles.size());
        for (IdmIdentityDto identity : identities) {
            List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
            assertEquals(1, allByIdentity.size());
        }
    } finally {
        identityService.deleteAll(identities);
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with IdmIdentityRoleFilter

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

the class IdentityContractExpirationTaskExecutorIntegrationTest method testExpiredRole.

@Test
public void testExpiredRole() {
    getHelper().disable(IdentityContractEndProcessor.class);
    // 
    try {
        IdmIdentityDto identity = getHelper().createIdentity();
        IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
        // 
        // normal and business role
        IdmRoleDto roleOne = getHelper().createRole();
        IdmRoleDto roleRoot = getHelper().createRole();
        IdmRoleDto roleSub = getHelper().createRole();
        getHelper().createRoleComposition(roleRoot, roleSub);
        // 
        // assign roles
        getHelper().assignRoles(contract, roleRoot, roleOne);
        // 
        // expire contract
        contract.setValidTill(LocalDate.now().minusDays(2));
        contract = getHelper().getService(IdmIdentityContractService.class).save(contract);
        // 
        // test after create before lrt is executed
        IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
        filter.setIdentityContractId(contract.getId());
        List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
        // 
        Assert.assertEquals(3, assignedRoles.size());
        Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleOne.getId())));
        Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleRoot.getId())));
        Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleSub.getId())));
        // 
        IdentityContractExpirationTaskExecutor lrt = new IdentityContractExpirationTaskExecutor();
        lrt.init(null);
        lrtManager.executeSync(lrt);
        // 
        assignedRoles = identityRoleService.find(filter, null).getContent();
        // 
        Assert.assertTrue(assignedRoles.isEmpty());
    } finally {
        getHelper().enable(IdentityContractEndProcessor.class);
    }
}
Also used : IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) IdentityContractEndProcessor(eu.bcvsolutions.idm.core.model.event.processor.contract.IdentityContractEndProcessor) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Assert(org.junit.Assert) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)116 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)85 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)84 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)81 Test (org.junit.Test)72 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)67 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)46 UUID (java.util.UUID)41 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)39 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)38 List (java.util.List)38 Autowired (org.springframework.beans.factory.annotation.Autowired)38 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)33 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)31 LocalDate (java.time.LocalDate)31 Assert (org.junit.Assert)28 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)27 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)25 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)25 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)25