Search in sources :

Example 71 with IdmIdentityRoleFilter

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

the class DefaultSysSystemMappingService method getMappingContext.

@Override
public MappingContext getMappingContext(SysSystemMappingDto mapping, SysSystemEntityDto systemEntity, AbstractDto dto, SysSystemDto system) {
    Assert.notNull(mapping, "Mapping cannot be null!");
    Assert.notNull(systemEntity, "System entity cannot be null!");
    Assert.notNull(system, "System cannot be null!");
    // Create new context.
    MappingContext mappingContext = new MappingContext();
    if (dto == null) {
        return mappingContext;
    }
    if ((mapping.isAddContextIdentityRoles() || mapping.isAddContextIdentityRolesForSystem()) && dto instanceof IdmIdentityDto) {
        IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
        identityRoleFilter.setIdentityId(dto.getId());
        List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
        if (mapping.isAddContextIdentityRoles()) {
            // Set all identity-roles to the context.
            mappingContext.setIdentityRoles(identityRoles);
        }
        if (mapping.isAddContextIdentityRolesForSystem()) {
            Assert.notNull(system.getId(), "System identifier is required.");
            List<IdmIdentityRoleDto> identityRolesForSystem = Lists.newArrayList();
            AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
            identityAccountFilter.setIdentityId(dto.getId());
            identityAccountFilter.setSystemId(system.getId());
            List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
            // Filtering only identity-roles for this system.
            identityAccounts.forEach(identityAccount -> {
                identityRolesForSystem.addAll(identityRoles.stream().filter(identityRole -> identityRole.getId().equals(identityAccount.getIdentityRole())).collect(Collectors.toList()));
            });
            // Set identity-roles for this system to the context.
            mappingContext.setIdentityRolesForSystem(identityRolesForSystem);
        }
    }
    if (mapping.isAddContextContracts() && dto instanceof IdmIdentityDto) {
        // Set all identity contracts to the context.
        mappingContext.setContracts(identityContractService.findAllByIdentity(dto.getId()));
    }
    if (mapping.isAddContextConnectorObject()) {
        // Set connector object to the context.
        mappingContext.setConnectorObject(systemEntityService.getConnectorObject(systemEntity));
    }
    String script = mapping.getMappingContextScript();
    if (StringUtils.isEmpty(script)) {
        return mappingContext;
    } else {
        Map<String, Object> variables = new HashMap<>();
        variables.put(SysSystemAttributeMappingService.ACCOUNT_UID, systemEntity.getUid());
        variables.put(SysSystemAttributeMappingService.SYSTEM_KEY, system);
        variables.put(SysSystemAttributeMappingService.ENTITY_KEY, dto);
        variables.put(SysSystemAttributeMappingService.CONTEXT_KEY, mappingContext);
        // Add default script evaluator, for call another scripts
        variables.put(AbstractScriptEvaluator.SCRIPT_EVALUATOR, pluginExecutors.getPluginFor(IdmScriptCategory.MAPPING_CONTEXT));
        // Add access for script evaluator
        List<Class<?>> extraClass = new ArrayList<>();
        extraClass.add(AbstractScriptEvaluator.Builder.class);
        extraClass.add(IcConnectorObject.class);
        // 
        Object result = groovyScriptService.evaluate(script, variables, extraClass);
        if (result instanceof MappingContext) {
            return (MappingContext) result;
        } else {
            throw new ProvisioningException(AccResultCode.MAPPING_CONTEXT_SCRIPT_RETURNS_WRONG_TYPE, ImmutableMap.of("system", system.getCode()));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) AbstractScriptEvaluator(eu.bcvsolutions.idm.core.script.evaluator.AbstractScriptEvaluator) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 72 with IdmIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter 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 73 with IdmIdentityRoleFilter

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

the class IdentityContractSyncTest method testUpdateContractWithAutomaticRoles.

@Test
public void testUpdateContractWithAutomaticRoles() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    // create first contract with validity and automatic role
    String positionCode = getHelper().createName();
    IdmTreeNodeDto node = getHelper().createTreeNode();
    IdmRoleDto role = getHelper().createRole();
    getHelper().createAutomaticRole(role, node);
    IdmIdentityContractDto contract = new IdmIdentityContractDto();
    contract.setIdentity(identity.getId());
    contract.setValidFrom(LocalDate.now().minusMonths(1));
    contract.setValidTill(LocalDate.now().plusMonths(1));
    contract.setDescription(positionCode);
    contract.setPosition(positionCode);
    contract.setWorkPosition(node.getId());
    contract = contractService.save(contract);
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue(positionCode);
    Assert.assertEquals(1, contractService.find(contractFilter, null).getTotalElements());
    IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
    identityRoleFilter.setIdentityContractId(contract.getId());
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertNotNull(assignedRoles.get(0).getValidFrom());
    Assert.assertNotNull(assignedRoles.get(0).getValidTill());
    Assert.assertEquals(contract.getValidFrom(), assignedRoles.get(0).getValidFrom());
    Assert.assertEquals(contract.getValidTill(), assignedRoles.get(0).getValidTill());
    // create target system entity
    this.getBean().createContractData(positionCode, identity.getUsername(), null, Boolean.TRUE.toString(), node.getId().toString(), null, null);
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 1);
    Assert.assertFalse(log.isRunning());
    List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contracts.size());
    Assert.assertEquals(contract.getId(), contracts.get(0).getId());
    Assert.assertEquals(identity.getId(), contracts.get(0).getIdentity());
    Assert.assertNull(contracts.get(0).getValidTill());
    Assert.assertNull(contracts.get(0).getValidFrom());
    // 
    assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertNull(assignedRoles.get(0).getValidFrom());
    Assert.assertNull(assignedRoles.get(0).getValidTill());
    // Delete log
    syncLogService.delete(log);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) 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 74 with IdmIdentityRoleFilter

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

the class RoleWorkflowAdSyncTest method n92_testSyncWithWfSituationLinkedResolveMember.

@Test
public void n92_testSyncWithWfSituationLinkedResolveMember() {
    createRolesInSystem();
    final String newDN = "CN=" + ROLE_NAME + ",OU=Flat,OU=Pardubice,DC=bcvsolutions,DC=eu";
    this.getBean().initIdentityData(ROLE_NAME, newDN);
    String valueOfMemberAtt = "" + System.currentTimeMillis();
    String nameOfEav = "externalIdentifier";
    configurationService.setValue("idm.pub.acc.syncRole.identity.eav.externalIdentifier.code", nameOfEav);
    configurationService.setValue("idm.pub.acc.syncRole.roles.attributeNameOfMembership", helper.getSchemaColumnName(ATTRIBUTE_MEMBER));
    configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", true);
    IdmIdentityDto identity = this.getHelper().createIdentity();
    IdmFormAttributeFilter attributeFilter = new IdmFormAttributeFilter();
    attributeFilter.setCode(nameOfEav);
    IdmFormAttributeDto formAttribute = formAttributeService.find(attributeFilter, null).getContent().stream().findFirst().orElse(null);
    Assert.assertNotNull(formAttribute);
    helper.setEavValue(identity, formAttribute, IdmIdentity.class, valueOfMemberAtt, PersistentType.SHORTTEXT);
    this.getBean().deleteAllResourceData();
    this.getBean().addRoleToResource(ROLE_NAME, ATTRIBUTE_DN, valueOfMemberAtt);
    IdmRoleFilter roleFilter = new IdmRoleFilter();
    roleFilter.setText(ROLE_NAME);
    List<IdmRoleDto> roles = roleService.find(roleFilter, null).getContent();
    // role is in already synced ind idm
    Assert.assertEquals(1, roles.size());
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    List<IdmIdentityRoleDto> content = identityRoleService.find(filter, null).getContent();
    // identity does not have assigned this role
    Assert.assertEquals(0, content.size());
    SysSystemDto systemDto = systemService.getByCode(SYSTEM_NAME);
    Assert.assertNotNull(systemDto);
    SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
    syncFilter.setSystemId(systemDto.getId());
    List<AbstractSysSyncConfigDto> syncConfig = syncConfigService.find(syncFilter, null).getContent();
    // find synchronization config to start sync
    Assert.assertEquals(1, syncConfig.size());
    // Start sync
    helper.startSynchronization(syncConfig.get(0));
    SysSyncLogDto log = checkSyncLog(syncConfig.get(0), SynchronizationActionType.LINKED, 1, OperationResultType.WF);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    roles = roleService.find(roleFilter, null).getContent();
    Assert.assertEquals(1, roles.size());
    content = identityRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    identityRoleService.delete(content.get(0));
    // Delete log
    syncLogService.delete(log);
    configurationService.deleteValue("idm.pub.acc.syncRole.provisioningOfIdentities.system.code");
    configurationService.deleteValue("idm.pub.acc.syncRole.system.mapping.attributeMemberOf");
    configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", false);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 75 with IdmIdentityRoleFilter

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

the class IdentityDeleteBulkAction method end.

@Override
protected OperationResult end(OperationResult result, Exception exception) {
    if (exception != null || (result != null && OperationState.EXECUTED != result.getState())) {
        return super.end(result, exception);
    }
    // success - force by default
    for (UUID identityId : processedIds) {
        IdmIdentityDto identity = getService().get(identityId);
        if (identity != null) {
            // delete identity contracts => contract related records are  removed asynchornously, but contract itself will be removed here
            for (IdmIdentityContractDto contract : contractService.findAllByIdentity(identityId)) {
                // check assigned roles again - can be assigned in the meantime ...
                IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
                UUID contractId = contract.getId();
                identityRoleFilter.setIdentityContractId(contractId);
                if (identityRoleService.count(identityRoleFilter) > 0) {
                    return super.end(result, new ResultCodeException(CoreResultCode.CONTRACT_DELETE_FAILED_ROLE_ASSIGNED, ImmutableMap.of("contract", contractId)));
                }
                contractService.deleteInternal(contract);
                // 
                LOG.debug("Contract [{}] deleted.", contractId);
                // clean up all states
                entityStateManager.deleteStates(contract, null, null);
            }
            // 
            // Delete all role requests where is this identity applicant - processed asynchronous requests should be deleted here
            IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
            roleRequestFilter.setApplicantId(identityId);
            roleRequestService.find(roleRequestFilter, null).forEach(request -> {
                roleRequestService.delete(request);
            });
            // 
            identityService.deleteInternal(identity);
            // 
            LOG.debug("Identity [{}] deleted.", identity.getUsername());
        } else {
            LOG.debug("Identity [{}] already deleted.", identityId);
        }
        // clean up all states
        entityStateManager.deleteStates(new IdmIdentityDto(identityId), null, null);
    }
    return super.end(result, exception);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

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