Search in sources :

Example 26 with IdmTreeTypeDto

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

the class DefaultTestHelper method createTreeType.

@Override
public IdmTreeTypeDto createTreeType(String name) {
    IdmTreeTypeDto treeType = new IdmTreeTypeDto();
    name = name == null ? createName() : name;
    treeType.setCode(name);
    treeType.setName(name);
    return treeTypeService.save(treeType);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)

Example 27 with IdmTreeTypeDto

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

the class ContractSliceSynchronizationExecutor method findTreeNode.

private IdmTreeNodeDto findTreeNode(Object value, SynchronizationContext context) {
    if (value instanceof Serializable) {
        // Find by UUID
        context.getLogItem().addToLog(MessageFormat.format("Work position - try find directly by transformed value [{0}]!", value));
        IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, (Serializable) value);
        if (node != null) {
            IdmTreeTypeDto treeTypeDto = DtoUtils.getEmbedded(node, IdmTreeNode_.treeType);
            context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] (in tree type [{2}]) was found directly by transformed value [{0}]!", value, node.getCode(), treeTypeDto.getCode()));
            return node;
        }
        context.getLogItem().addToLog(MessageFormat.format("Work position - was not not found directly from transformed value [{0}]!", value));
        if (value instanceof String && StringUtils.isNotEmpty((String) value)) {
            // Find by code in default tree type
            SysSyncContractConfigDto config = this.getConfig(context);
            if (config.getDefaultTreeType() == null) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - we cannot finding node by code [{0}], because default tree type is not set (in sync configuration)!", value));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            }
            IdmTreeNodeFilter treeNodeFilter = new IdmTreeNodeFilter();
            IdmTreeTypeDto defaultTreeType = DtoUtils.getEmbedded(config, SysSyncContractConfig_.defaultTreeType);
            treeNodeFilter.setTreeTypeId(config.getDefaultTreeType());
            treeNodeFilter.setCode((String) value);
            context.getLogItem().addToLog(MessageFormat.format("Work position - try find in default tree type [{1}] with code [{0}]!", value, defaultTreeType.getCode()));
            List<IdmTreeNodeDto> nodes = treeNodeService.find(treeNodeFilter, null).getContent();
            if (nodes.isEmpty()) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - none node found for code [{0}]!", value));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            } else {
                context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] was found for code [{0}]!", value, nodes.get(0).getId()));
                return nodes.get(0);
            }
        }
    } else {
        context.getLogItem().addToLog(MessageFormat.format("Warning! - Work position cannot be found, because transformed value [{0}] is not Serializable!", value));
        this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
    }
    return null;
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) Serializable(java.io.Serializable) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)

Example 28 with IdmTreeTypeDto

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

the class DefaultUniformPasswordManagerIntegrationTest method testUniformPasswordInIdM.

@Test
public void testUniformPasswordInIdM() {
    try {
        // Turn on an async execution.
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
        getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
        SysSystemDto contractSystem = initData();
        Assert.assertNotNull(contractSystem);
        IdmTreeTypeDto treeType = helper.createTreeType();
        AbstractSysSyncConfigDto config = doCreateSyncConfig(contractSystem, treeType);
        Assert.assertTrue(config instanceof SysSyncContractConfigDto);
        SysSystemDto targetSystemOne = helper.createTestResourceSystem(true);
        // Create system two with account suffix "_targetSystemTwo".
        String targetSystemTwoSuffix = "_targetSystemTwo";
        SysSystemDto targetSystemTwo = helper.createTestResourceSystem(true);
        // Create uniform password definition.
        AccUniformPasswordDto uniformPasswordDef = createUniformPasswordDef(targetSystemOne, targetSystemTwo);
        // Enable change in the IdM.
        uniformPasswordDef.setChangeInIdm(true);
        uniformPasswordService.save(uniformPasswordDef);
        SysSystemMappingDto provisioningMapping = systemMappingService.findProvisioningMapping(targetSystemTwo.getId(), SystemEntityType.IDENTITY);
        List<SysSystemAttributeMappingDto> attributeMappingDtos = schemaAttributeMappingService.findBySystemMapping(provisioningMapping);
        SysSystemAttributeMappingDto uidAttribute = schemaAttributeMappingService.getUidAttribute(attributeMappingDtos, targetSystemTwo);
        uidAttribute.setTransformToResourceScript("return attributeValue + \"" + targetSystemTwoSuffix + "\"");
        schemaAttributeMappingService.save(uidAttribute);
        IdmRoleDto automaticRoleTreeOne = helper.createRole();
        helper.createRoleSystem(automaticRoleTreeOne, targetSystemOne);
        IdmTreeNodeDto treeNodeOne = helper.createTreeNode(treeType, null);
        helper.createAutomaticRole(automaticRoleTreeOne, treeNodeOne);
        IdmRoleDto automaticRoleTreeTwo = helper.createRole();
        helper.createRoleSystem(automaticRoleTreeTwo, targetSystemTwo);
        IdmTreeNodeDto treeNodeTwo = helper.createTreeNode(treeType, null);
        helper.createAutomaticRole(automaticRoleTreeTwo, treeNodeTwo);
        IdmIdentityDto ownerOne = helper.createIdentityOnly();
        List<TestContractResource> contractResources = Lists.newArrayList(this.createContract("1", ownerOne.getUsername(), null, "true", treeNodeOne.getCode(), null, null, null), this.createContract("2", ownerOne.getUsername(), null, "false", treeNodeTwo.getCode(), null, null, null));
        this.getBean().initContractData(contractResources);
        IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
        contractFilter.setIdentity(ownerOne.getId());
        contractService.find(contractFilter, null).getContent().forEach(contract -> contractService.delete(contract));
        Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
        IdmIdentityFilter identityFilter = new IdmIdentityFilter();
        identityFilter.setAddPasswordMetadata(true);
        ownerOne = identityService.get(ownerOne.getId(), identityFilter);
        // Identities should be in the CREATED state.
        Assert.assertEquals(IdentityState.CREATED, ownerOne.getState());
        Assert.assertNull(ownerOne.getPassword());
        Assert.assertNull(ownerOne.getPasswordMetadata());
        SynchronizationSchedulableTaskExecutor lrt = new SynchronizationSchedulableTaskExecutor(config.getId());
        LongRunningFutureTask<Boolean> longRunningFutureTask = longRunningTaskManager.execute(lrt);
        UUID transactionIdLrt = longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getTransactionId();
        // Waiting for the LRT will be running.
        getHelper().waitForResult(res -> {
            return !longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).isRunning();
        }, 50, 40);
        // Waiting for the LRT will be EXECUTED.
        getHelper().waitForResult(res -> {
            return longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState() != OperationState.EXECUTED;
        }, 250, 100);
        Assert.assertEquals(longRunningTaskService.get(longRunningFutureTask.getExecutor().getLongRunningTaskId()).getResultState(), OperationState.EXECUTED);
        SysSyncLogDto log = helper.checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.SUCCESS);
        Assert.assertFalse(log.isRunning());
        Assert.assertFalse(log.isContainsError());
        UUID transactionId = log.getTransactionId();
        Assert.assertNotNull(transactionId);
        Assert.assertEquals(transactionIdLrt, transactionId);
        contractFilter.setIdentity(ownerOne.getId());
        Assert.assertEquals(2, contractService.count(contractFilter));
        ownerOne = identityService.get(ownerOne.getId());
        // Identities should have a valid state.
        Assert.assertEquals(IdentityState.VALID, ownerOne.getState());
        // Waiting for removing entity state.
        IdmIdentityDto finalOwnerOne = ownerOne;
        getHelper().waitForResult(res -> {
            return uniformPasswordManager.getEntityState(finalOwnerOne.getId(), IdmIdentityDto.class, transactionId) != null;
        }, 50, 100);
        // LRT ended, entityStates must be removed.
        IdmEntityStateDto entityStateDtoOwnerOne = uniformPasswordManager.getEntityState(ownerOne.getId(), IdmIdentityDto.class, transactionId);
        Assert.assertNull(entityStateDtoOwnerOne);
        TestResource resourceOwnerOne = helper.findResource(ownerOne.getUsername());
        Assert.assertNotNull(resourceOwnerOne);
        TestResource resourceOwnerTwo = helper.findResource(ownerOne.getUsername() + targetSystemTwoSuffix);
        Assert.assertNotNull(resourceOwnerTwo);
        String passwordOwnerOne = resourceOwnerOne.getPassword();
        String passwordOwnerTwo = resourceOwnerTwo.getPassword();
        Assert.assertNotNull(passwordOwnerOne);
        Assert.assertNotNull(passwordOwnerTwo);
        Assert.assertEquals(passwordOwnerOne, passwordOwnerTwo);
        // Change in the IdM is enabled.
        ownerOne = identityService.get(ownerOne.getId(), identityFilter);
        Assert.assertNotNull(ownerOne.getPasswordMetadata());
        // One uniform password notification was send.
        IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
        notificationFilter.setRecipient(ownerOne.getUsername());
        notificationFilter.setNotificationType(IdmEmailLog.class);
        notificationFilter.setTopic(CoreModule.TOPIC_UNIFORM_PASSWORD_SET);
        List<IdmNotificationLogDto> notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
        Assert.assertEquals(1, notificationLogDtos.size());
        // None a new password notification was send.
        notificationFilter.setTopic(AccModuleDescriptor.TOPIC_NEW_PASSWORD);
        notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
        Assert.assertEquals(0, notificationLogDtos.size());
        // None password set notification was send.
        notificationFilter.setTopic(CoreModule.TOPIC_PASSWORD_SET);
        notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
        Assert.assertEquals(0, notificationLogDtos.size());
        // None password change notification was send.
        notificationFilter.setTopic(CoreModule.TOPIC_PASSWORD_CHANGED);
        notificationLogDtos = notificationLogService.find(notificationFilter, null).getContent();
        Assert.assertEquals(0, notificationLogDtos.size());
        // Delete log
        syncLogService.delete(log);
        // Delete identities.
        identityService.delete(ownerOne);
        // Delete uniform password def.
        uniformPasswordService.delete(uniformPasswordDef);
    } finally {
        // Turn off an async execution.
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
        getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
    }
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AccUniformPasswordDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) TestContractResource(eu.bcvsolutions.idm.acc.entity.TestContractResource) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) SynchronizationSchedulableTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.SynchronizationSchedulableTaskExecutor) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 29 with IdmTreeTypeDto

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

the class DefaultSysSystemMappingServiceIntegrationTest method treeTypeIdFilterTest.

@Test
public void treeTypeIdFilterTest() {
    IdmBasePermission permission = IdmBasePermission.ADMIN;
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    IdmTreeTypeDto treeType = new IdmTreeTypeDto();
    treeType.setName("SomeTreeTypeName");
    treeType.setCode("CodeCodeCodeCode");
    treeType = treeTypeService.save(treeType);
    IdmTreeTypeDto treeType2 = new IdmTreeTypeDto();
    treeType2.setName("SomeTreeTypeName2");
    treeType2.setCode("CodeCodeCodeCode2");
    treeType2 = treeTypeService.save(treeType2);
    SysSystemDto system = createSystem();
    SysSchemaObjectClassDto objectClass = createObjectClass(system);
    SysSystemMappingDto mappingSystem1 = testHelper.createMappingSystem(entityType, objectClass);
    mappingSystem1.setTreeType(treeType.getId());
    mappingSystem1 = mappingService.save(mappingSystem1);
    SysSystemMappingDto mappingSystem2 = testHelper.createMappingSystem(entityType, objectClass);
    mappingSystem2.setTreeType(treeType2.getId());
    mappingSystem2 = mappingService.save(mappingSystem2);
    SysSystemMappingFilter filter = new SysSystemMappingFilter();
    filter.setTreeTypeId(mappingSystem1.getTreeType());
    Page<SysSystemMappingDto> result = mappingService.find(filter, null, permission);
    assertEquals(1, result.getTotalElements());
    assertTrue(result.getContent().contains(mappingSystem1));
    assertFalse(result.getContent().contains(mappingSystem2));
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with IdmTreeTypeDto

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

the class DefaultTreeSynchronizationServiceTest method initData.

private void initData() {
    // create test system
    system = helper.createSystem("test_tree_resource");
    system.setName(SYSTEM_NAME);
    system = systemService.save(system);
    // key to EAV
    IdmFormDefinitionDto formDefinition = systemService.getConnectorFormDefinition(system);
    formService.saveValues(system, formDefinition, "keyColumn", ImmutableList.of("ID"));
    // generate schema for system
    List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
    IdmTreeTypeDto treeType = new IdmTreeTypeDto();
    treeType.setCode(TREE_TYPE_TEST);
    treeType.setName(TREE_TYPE_TEST);
    treeType = treeTypeService.save(treeType);
    // Create synchronization mapping
    SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
    syncSystemMapping.setName("default_" + System.currentTimeMillis());
    syncSystemMapping.setEntityType(SystemEntityType.TREE);
    syncSystemMapping.setTreeType(treeType.getId());
    syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
    syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
    final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
    createMapping(system, syncMapping);
    deleteAllResourceData();
    initTreeData();
    syncConfigService.find(null).getContent().forEach(config -> {
        syncConfigService.delete(config);
    });
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Aggregations

IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)123 Test (org.junit.Test)91 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)89 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)64 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)44 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)32 UUID (java.util.UUID)26 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)21 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)21 Transactional (org.springframework.transaction.annotation.Transactional)19 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)18 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)18 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)18 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)13 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)11 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)11 LocalDate (java.time.LocalDate)10