Search in sources :

Example 1 with IdmIdentityContract_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceIntegrationTest method testAutomaticRolesRemovalAfterContractEnds.

@Test
public void testAutomaticRolesRemovalAfterContractEnds() {
    // automatic roles by tree structure
    prepareAutomaticRoles();
    // automatic role by attribute on contract
    String autoPosition = getHelper().createName();
    IdmRoleDto autoAttributeRole = getHelper().createRole();
    IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(autoAttributeRole.getId());
    getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, autoPosition);
    // 
    // prepare identity, contract, direct roles and automatic roles
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
    contract.setIdentity(identity.getId());
    contract.setValidFrom(LocalDate.now().minusDays(1));
    contract.setValidTill(LocalDate.now().plusMonths(1));
    contract.setWorkPosition(nodeD.getId());
    contract.setMain(true);
    contract.setDescription("test-node-d");
    contract.setPosition(autoPosition);
    contract = service.save(contract);
    UUID contractId = contract.getId();
    IdmRoleDto directRole = getHelper().createRole();
    getHelper().createIdentityRole(contract, directRole);
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(5, identityRoles.size());
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleA.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleB.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleC.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return directRole.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return autoAttributeRole.getId().equals(ir.getRole());
    }));
    // 
    try {
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
        // 
        // end contract - all roles should be removed, after asynchronous role request ends
        contract.setValidTill(LocalDate.now().minusDays(1));
        contract = service.save(contract);
        // 
        Assert.assertFalse(contract.isValidNowOrInFuture());
        // 
        getHelper().waitForResult(res -> {
            return !identityRoleService.findAllByContract(contractId).isEmpty();
        }, 300, Integer.MAX_VALUE);
        getHelper().waitForResult(res -> {
            IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
            filter.setRunning(Boolean.TRUE);
            // 
            return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
        });
        // 
        identityRoles = identityRoleService.findAllByContract(contract.getId());
        Assert.assertTrue(identityRoles.isEmpty());
        // 
        service.delete(contract);
    } finally {
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
    }
}
Also used : Lists(org.testng.collections.Lists) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ContractPositionEventType(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Set(java.util.Set) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) RemoveAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.RemoveAutomaticRoleTaskExecutor) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) PermissionContext(eu.bcvsolutions.idm.core.api.dto.filter.PermissionContext) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) ApplicationContext(org.springframework.context.ApplicationContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) PrivateIdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.IdentityConfiguration) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) 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 2 with IdmIdentityContract_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.

the class IdmIdentityContractControllerRestTest method testSortByPrimeContract.

@Test
public void testSortByPrimeContract() {
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityThree = getHelper().createIdentity((GuardedString) null);
    // other contract jus for sure
    IdmIdentityContractDto contractOther = getHelper().createContract(identityTwo);
    // 
    IdmIdentityContractDto contract = getHelper().createContract(identityOne);
    contract.setValidFrom(LocalDate.now().minusDays(5));
    contract.setState(ContractState.DISABLED);
    contract.setMain(true);
    IdmIdentityContractDto contractOne = contractService.save(contract);
    // 
    contract = getHelper().createContract(identityOne);
    contract.setValidFrom(LocalDate.now().minusDays(4));
    // two
    contractService.save(contract);
    // 
    contract = getHelper().createContract(identityOne);
    contract.setValidFrom(LocalDate.now().minusDays(3));
    // three
    contractService.save(contract);
    // 
    contract = getHelper().createContract(identityOne);
    contract.setMain(true);
    contract.setValidFrom(LocalDate.now().minusDays(2));
    IdmIdentityContractDto primeContract = contractService.save(contract);
    // 
    List<IdmIdentityContractDto> contracts = controller.find((IdmIdentityContractFilter) null, PageRequest.of(0, 1), null).getContent();
    Assert.assertFalse(contracts.isEmpty());
    // 
    IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
    contracts = controller.find((IdmIdentityContractFilter) null, PageRequest.of(0, 1), null).getContent();
    Assert.assertFalse(contracts.isEmpty());
    // 
    filter.setIdentity(identityOne.getId());
    contracts = controller.find(filter, PageRequest.of(0, 5), null).getContent();
    Assert.assertEquals(4, contracts.size());
    Assert.assertTrue(contracts.stream().allMatch(c -> !c.getId().equals(contractOther.getId())));
    Assert.assertEquals(primeContract.getId(), contracts.get(0).getId());
    // 
    filter.setIdentity(identityThree.getId());
    contracts = controller.find(filter, PageRequest.of(0, 5), null).getContent();
    Assert.assertTrue(contracts.isEmpty());
    // 
    filter.setIdentity(identityOne.getId());
    contracts = controller.find(filter, PageRequest.of(0, 5, Sort.by(Direction.ASC, IdmIdentityContract_.validFrom.getName())), null).getContent();
    Assert.assertEquals(4, contracts.size());
    Assert.assertEquals(contractOne.getId(), contracts.get(0).getId());
}
Also used : IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) PageRequest(org.springframework.data.domain.PageRequest) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) PrivateIdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration) LocalDate(java.time.LocalDate) After(org.junit.After) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 3 with IdmIdentityContract_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.

the class IdentityContractSyncTest method testCreateContractWithAutomaticRoleByEavAttribute.

@Test
public void testCreateContractWithAutomaticRoleByEavAttribute() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    // 
    // create form definition, roles, automatic role etc.
    IdmRoleDto roleContract = getHelper().createRole();
    IdmRoleDto subRoleContract = getHelper().createRole();
    getHelper().createRoleComposition(roleContract, subRoleContract);
    // sync supports default definition only
    IdmFormAttributeDto formAttribute = new IdmFormAttributeDto(getHelper().createName());
    IdmFormAttributeDto formAttributeContract = formService.saveAttribute(IdmIdentityContractDto.class, formAttribute);
    // 
    IdmAutomaticRoleAttributeDto automaticRoleContract = getHelper().createAutomaticRole(roleContract.getId());
    getHelper().createAutomaticRoleRule(automaticRoleContract.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, formAttributeContract.getId(), "mockContract");
    // 
    // create mapping to eav attribute - leader = eav
    SysSystemMappingDto syncSystemMapping = systemMappingService.get(config.getSystemMapping());
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemMappingId(syncSystemMapping.getId());
    SysSystemAttributeMappingDto leaderAttributeMapping = schemaAttributeMappingService.findBySystemMappingAndName(syncSystemMapping.getId(), "leader");
    leaderAttributeMapping.setEntityAttribute(false);
    leaderAttributeMapping.setExtendedAttribute(true);
    leaderAttributeMapping.setIdmPropertyName(formAttributeContract.getCode());
    schemaAttributeMappingService.save(leaderAttributeMapping);
    // 
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    String positionCode = getHelper().createName();
    this.getBean().createContractData(positionCode, identity.getUsername(), "mockContract", Boolean.TRUE.toString(), null, null, null);
    // 
    IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
    identityRoleFilter.setIdentityId(identity.getId());
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
    Assert.assertFalse(log.isRunning());
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setIdentity(identity.getId());
    contractFilter.setAddEavMetadata(Boolean.TRUE);
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue(positionCode);
    List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contracts.size());
    Assert.assertEquals("mockContract", contracts.get(0).getEavs().stream().filter(fi -> fi.getFormDefinition().isMain()).findFirst().get().getValues().stream().filter(v -> v.getFormAttribute().equals(formAttributeContract.getId())).findFirst().get().getShortTextValue());
    assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
    Assert.assertEquals(2, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleContract.getId())));
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subRoleContract.getId())));
    // Delete log
    syncLogService.delete(log);
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) IdmContractPosition_(eu.bcvsolutions.idm.core.model.entity.IdmContractPosition_) SynchronizationUnlinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationUnlinkedActionType) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) AccContractAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractAccountService) HrEndContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEndContractProcess) Page(org.springframework.data.domain.Page) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) Assert.assertFalse(org.junit.Assert.assertFalse) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) ContractSynchronizationExecutor(eu.bcvsolutions.idm.acc.service.impl.ContractSynchronizationExecutor) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Before(org.junit.Before) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) HrContractExclusionProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrContractExclusionProcess) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) EntityManager(javax.persistence.EntityManager) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) Assert(org.junit.Assert) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) Assert.assertEquals(org.junit.Assert.assertEquals) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) TestContractResource(eu.bcvsolutions.idm.acc.entity.TestContractResource) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) After(org.junit.After) SynchronizationMissingEntityActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationMissingEntityActionType) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) List(java.util.List) Query(javax.persistence.Query) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) LocalDate(java.time.LocalDate) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) InitApplicationData(eu.bcvsolutions.idm.InitApplicationData) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmTreeTypeService(eu.bcvsolutions.idm.core.api.service.IdmTreeTypeService) IdmContractGuarantee_(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee_) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) ApplicationContext(org.springframework.context.ApplicationContext) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with IdmIdentityContract_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.

the class IdentityRoleDeleteProvisioningProcessor method process.

@SuppressWarnings("unchecked")
@Override
public EventResult<IdmIdentityRoleDto> process(EntityEvent<IdmIdentityRoleDto> event) {
    IdmIdentityRoleDto identityRole = event.getContent();
    // If for this role doesn't exists any mapped system, then is provisioning useless!
    UUID roleId = identityRole.getRole();
    SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
    roleSystemFilter.setRoleId(roleId);
    long numberOfMappedSystem = roleSystemService.count(roleSystemFilter);
    if (numberOfMappedSystem == 0) {
        return new DefaultEventResult<>(event, this);
    }
    // TODO: Optimalization - load identity by identity-role with filter
    IdmIdentityContractDto identityContract = identityContractService.get(identityRole.getIdentityContract());
    IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity);
    Serializable accountsIdsObj = event.getProperties().get(AccAccountManagementService.ACCOUNT_IDS_FOR_DELETED_IDENTITY_ROLE);
    List<UUID> accountsIds = null;
    if (accountsIdsObj instanceof List) {
        accountsIds = (List<UUID>) accountsIdsObj;
    }
    if (accountsIds == null) {
        // We don't know about specific accounts, so we will execute provisioning for all accounts.
        LOG.debug("Call provisioning for identity [{}]", identity.getUsername());
        provisioningService.doProvisioning(identity);
        return new DefaultEventResult<>(event, this);
    }
    // If default creation of accounts is disabled for this role-system (or system is in a cross-domain group), then relation between identity
    // and account may not exist. In this scenario we have to made provisioning too.
    // So we try to find these role-systems and its accounts.
    SysRoleSystemFilter roleSystemForProvisioningFilter = new SysRoleSystemFilter();
    roleSystemForProvisioningFilter.setRoleId(roleId);
    List<UUID> finalAccountsIds = accountsIds;
    roleSystemService.find(roleSystemForProvisioningFilter, null).getContent().stream().filter(roleSystem -> {
        if (!roleSystem.isCreateAccountByDefault()) {
            return true;
        } else {
            SysSystemGroupSystemFilter systemGroupSystemFilter = new SysSystemGroupSystemFilter();
            systemGroupSystemFilter.setCrossDomainsGroupsForRoleSystemId(roleSystem.getId());
            if ((identityRole.getRoleSystem() == null || roleSystem.getId().equals(identityRole.getRoleSystem()) && systemGroupSystemService.count(systemGroupSystemFilter) >= 1)) {
                // -> Provisioning should be made.
                return true;
            }
        }
        return false;
    }).forEach(roleSystem -> {
        AccAccountFilter accountFilter = new AccAccountFilter();
        accountFilter.setSystemId(roleSystem.getSystem());
        accountFilter.setIdentityId(identity.getId());
        accountService.find(accountFilter, null).getContent().stream().filter(account -> !finalAccountsIds.contains(account.getId())).forEach(account -> {
            finalAccountsIds.add(account.getId());
        });
    });
    finalAccountsIds.forEach(accountId -> {
        AccAccountDto account = accountService.get(accountId);
        if (account != null) {
            // Account could be null (was deleted).
            LOG.debug("Call provisioning for identity [{}] and account [{}]", identity.getUsername(), account.getUid());
            provisioningService.doProvisioning(account, identity);
        }
    });
    return new DefaultEventResult<>(event, this);
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) ProvisioningEvent(eu.bcvsolutions.idm.acc.event.ProvisioningEvent) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) LoggerFactory(org.slf4j.LoggerFactory) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) AccAccountManagementService(eu.bcvsolutions.idm.acc.service.api.AccAccountManagementService) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemGroupSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemGroupSystemService) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Description(org.springframework.context.annotation.Description) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) Logger(org.slf4j.Logger) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) Serializable(java.io.Serializable) List(java.util.List) Component(org.springframework.stereotype.Component) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Serializable(java.io.Serializable) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) List(java.util.List) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Aggregations

IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IdmIdentityContractService (eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService)4 IdmIdentityContract_ (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_)4 List (java.util.List)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)3 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)2 AccAccountService (eu.bcvsolutions.idm.acc.service.api.AccAccountService)2 PrivateIdentityConfiguration (eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration)2 ContractState (eu.bcvsolutions.idm.core.api.domain.ContractState)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)2 DtoUtils (eu.bcvsolutions.idm.core.api.utils.DtoUtils)2 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)2 LocalDate (java.time.LocalDate)2 UUID (java.util.UUID)2 After (org.junit.After)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2