Search in sources :

Example 16 with SysSystemAttributeMappingFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.

the class DefaultAccAccountManagementService method generateUID.

/**
 * Return UID for this identity and roleSystem. First will be find and use
 * transform script from roleSystem attribute. If isn't UID attribute for
 * roleSystem defined, then will be use default UID attribute handling.
 *
 * @param entity
 * @param roleSystem
 * @return
 */
@Override
public String generateUID(AbstractDto entity, SysRoleSystemDto roleSystem) {
    // Find attributes for this roleSystem
    SysRoleSystemAttributeFilter roleSystemAttrFilter = new SysRoleSystemAttributeFilter();
    roleSystemAttrFilter.setRoleSystemId(roleSystem.getId());
    List<SysRoleSystemAttributeDto> attributes = roleSystemAttributeService.find(roleSystemAttrFilter, null).getContent();
    List<SysRoleSystemAttributeDto> attributesUid = attributes.stream().filter(attribute -> {
        return attribute.isUid();
    }).collect(Collectors.toList());
    if (attributesUid.size() > 1) {
        IdmRoleDto roleDto = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.role, IdmRoleDto.class);
        DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
        SysSystemDto systemDto = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
        throw new ProvisioningException(AccResultCode.PROVISIONING_ROLE_ATTRIBUTE_MORE_UID, ImmutableMap.of("role", roleDto.getName(), "system", systemDto.getName()));
    }
    SysRoleSystemAttributeDto uidRoleAttribute = !attributesUid.isEmpty() ? attributesUid.get(0) : null;
    // script.
    if (uidRoleAttribute != null) {
        // Default values (values from schema attribute handling)
        SysSystemAttributeMappingDto systemAttributeMapping = systemAttributeMappingService.get(uidRoleAttribute.getSystemAttributeMapping());
        uidRoleAttribute.setSchemaAttribute(systemAttributeMapping.getSchemaAttribute());
        uidRoleAttribute.setTransformFromResourceScript(systemAttributeMapping.getTransformFromResourceScript());
        Object uid = systemAttributeMappingService.getAttributeValue(null, entity, uidRoleAttribute);
        if (uid == null) {
            SysSystemDto systemEntity = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
            throw new ProvisioningException(AccResultCode.PROVISIONING_GENERATED_UID_IS_NULL, ImmutableMap.of("system", systemEntity.getName()));
        }
        if (!(uid instanceof String)) {
            throw new ProvisioningException(AccResultCode.PROVISIONING_ATTRIBUTE_UID_IS_NOT_STRING, ImmutableMap.of("uid", uid));
        }
        return (String) uid;
    }
    SysSystemMappingDto mapping = systemMappingService.get(roleSystem.getSystemMapping());
    // If roleSystem UID was not found, then we use default UID schema
    // attribute handling
    SysSchemaObjectClassDto objectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    SysSystemDto system = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
    SysSystemAttributeMappingFilter systeAttributeMappingFilter = new SysSystemAttributeMappingFilter();
    systeAttributeMappingFilter.setSystemMappingId(mapping.getId());
    List<SysSystemAttributeMappingDto> schemaHandlingAttributes = systemAttributeMappingService.find(systeAttributeMappingFilter, null).getContent();
    SysSystemAttributeMappingDto uidAttribute = systemAttributeMappingService.getUidAttribute(schemaHandlingAttributes, system);
    return systemAttributeMappingService.generateUid(entity, uidAttribute);
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmIdentityRoleRepository(eu.bcvsolutions.idm.core.model.repository.IdmIdentityRoleRepository) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) AccAccountManagementService(eu.bcvsolutions.idm.acc.service.api.AccAccountManagementService) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) Service(org.springframework.stereotype.Service) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) ImmutableMap(com.google.common.collect.ImmutableMap) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) List(java.util.List) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) CollectionUtils(org.springframework.util.CollectionUtils) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) Optional(java.util.Optional) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) 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) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 17 with SysSystemAttributeMappingFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.

the class DefaultSynchronizationService method resolveMissingEntitySituation.

@Override
public SysSyncItemLogDto resolveMissingEntitySituation(String uid, SystemEntityType entityType, List<IcAttribute> icAttributes, UUID configId, String actionType) {
    Assert.notNull(uid);
    Assert.notNull(entityType);
    Assert.notNull(icAttributes);
    Assert.notNull(configId);
    Assert.notNull(actionType);
    AbstractSysSyncConfigDto config = synchronizationConfigService.get(configId);
    SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
    SysSchemaObjectClassDto sysSchemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    SysSystemDto system = DtoUtils.getEmbedded(sysSchemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
    SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
    attributeHandlingFilter.setSystemMappingId(mapping.getId());
    List<SysSystemAttributeMappingDto> mappedAttributes = attributeHandlingService.find(attributeHandlingFilter, null).getContent();
    SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
    // Little workaround, we have only IcAttributes ... we create IcObject manually
    IcConnectorObjectImpl icObject = new IcConnectorObjectImpl();
    icObject.setAttributes(icAttributes);
    icObject.setUidValue(uid);
    SynchronizationContext context = new SynchronizationContext();
    context.addUid(uid).addSystem(system).addConfig(config).addEntityType(entityType).addLogItem(itemLog).addMappedAttributes(mappedAttributes).addIcObject(icObject);
    getSyncExecutor(entityType).resolveMissingEntitySituation(SynchronizationMissingEntityActionType.valueOf(actionType), context);
    return itemLog;
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 18 with SysSystemAttributeMappingFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemServiceTest method duplicateSystemWithSynchronization.

@Test
public void duplicateSystemWithSynchronization() {
    String syncName = "test-sync-config";
    // create test system
    SysSystemDto system = helper.createTestResourceSystem(true);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(system.getId());
    // Number of schema attributes on original system
    int numberOfSchemaAttributesOrig = schemaAttributeService.find(schemaAttributeFilter, null).getContent().size();
    SysSystemMappingDto mappingOrig = helper.getDefaultMapping(system);
    // Number of mapping attributes on original system
    int numberOfMappingAttributesOrig = systemAttributeMappingService.findBySystemMapping(mappingOrig).size();
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemMappingId(mappingOrig.getId());
    List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
    SysSystemAttributeMappingDto nameAttribute = attributes.stream().filter(attribute -> {
        return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_NAME);
    }).findFirst().get();
    SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
        return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME);
    }).findFirst().get();
    SysSystemAttributeMappingDto emailAttribute = attributes.stream().filter(attribute -> {
        return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_EMAIL);
    }).findFirst().get();
    // create synchronization config
    AbstractSysSyncConfigDto syncConfigDuplicate = new SysSyncIdentityConfigDto();
    syncConfigDuplicate.setCustomFilter(true);
    syncConfigDuplicate.setSystemMapping(mappingOrig.getId());
    syncConfigDuplicate.setCorrelationAttribute(nameAttribute.getId());
    syncConfigDuplicate.setTokenAttribute(firstNameAttribute.getId());
    syncConfigDuplicate.setFilterAttribute(emailAttribute.getId());
    syncConfigDuplicate.setReconciliation(true);
    syncConfigDuplicate.setName(syncName);
    syncConfigDuplicate.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
    syncConfigDuplicate.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    syncConfigDuplicate.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY);
    syncConfigDuplicate.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    syncConfigDuplicate = syncConfigService.save(syncConfigDuplicate);
    SysSystemDto duplicatedSystem = systemService.duplicate(system.getId());
    // check duplicate
    systemService.checkSystem(duplicatedSystem);
    Assert.assertNotEquals(system.getId(), duplicatedSystem.getId());
    schemaAttributeFilter.setSystemId(duplicatedSystem.getId());
    // Number of schema attributes on duplicated system
    int numberOfSchemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent().size();
    Assert.assertEquals(numberOfSchemaAttributesOrig, numberOfSchemaAttributes);
    SysSystemMappingDto mapping = helper.getDefaultMapping(duplicatedSystem);
    // Number of mapping attributes on duplicated system
    int numberOfMappingAttributes = systemAttributeMappingService.findBySystemMapping(mapping).size();
    Assert.assertEquals(numberOfMappingAttributesOrig, numberOfMappingAttributes);
    // check synchronization config
    SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
    syncFilter.setSystemId(duplicatedSystem.getId());
    List<AbstractSysSyncConfigDto> configs = syncConfigService.find(syncFilter, null).getContent();
    Assert.assertEquals(1, configs.size());
    Assert.assertEquals(1, configs.size());
    AbstractSysSyncConfigDto configNew = configs.get(0);
    Assert.assertFalse(configNew.isEnabled());
    Assert.assertTrue(configNew.isReconciliation());
    Assert.assertEquals(syncName, configNew.getName());
    Assert.assertTrue(configNew.isCustomFilter());
    Assert.assertEquals(syncConfigDuplicate.getLinkedAction(), configNew.getLinkedAction());
    Assert.assertEquals(syncConfigDuplicate.getUnlinkedAction(), configNew.getUnlinkedAction());
    Assert.assertEquals(syncConfigDuplicate.getMissingEntityAction(), configNew.getMissingEntityAction());
    Assert.assertEquals(syncConfigDuplicate.getMissingAccountAction(), configNew.getMissingAccountAction());
    SysSystemAttributeMappingDto correlationAtt = schemaAttributeMappingService.get(configNew.getCorrelationAttribute());
    SysSystemAttributeMappingDto tokenAtt = schemaAttributeMappingService.get(configNew.getTokenAttribute());
    SysSystemAttributeMappingDto filterAtt = schemaAttributeMappingService.get(configNew.getFilterAttribute());
    Assert.assertEquals(nameAttribute.getName(), correlationAtt.getName());
    Assert.assertEquals(nameAttribute.getIdmPropertyName(), correlationAtt.getIdmPropertyName());
    Assert.assertEquals(firstNameAttribute.getName(), tokenAtt.getName());
    Assert.assertEquals(firstNameAttribute.getIdmPropertyName(), tokenAtt.getIdmPropertyName());
    Assert.assertEquals(emailAttribute.getName(), filterAtt.getName());
    Assert.assertEquals(emailAttribute.getIdmPropertyName(), filterAtt.getIdmPropertyName());
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 19 with SysSystemAttributeMappingFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemServiceTest method testReferentialIntegrity.

@Test
public void testReferentialIntegrity() {
    SysSystemDto system = new SysSystemDto();
    String systemName = "t_s_" + System.currentTimeMillis();
    system.setName(systemName);
    system = systemService.save(system);
    // object class
    SysSchemaObjectClassDto objectClass = new SysSchemaObjectClassDto();
    objectClass.setSystem(system.getId());
    objectClass.setObjectClassName("obj_class");
    objectClass = schemaObjectClassService.save(objectClass);
    SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
    objectClassFilter.setSystemId(system.getId());
    // schema attribute
    SysSchemaAttributeDto schemaAttribute = new SysSchemaAttributeDto();
    schemaAttribute.setObjectClass(objectClass.getId());
    schemaAttribute.setName("name");
    schemaAttribute.setClassType("class");
    schemaAttribute = schemaAttributeService.save(schemaAttribute);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(system.getId());
    // system entity handling
    SysSystemMappingDto systemMapping = new SysSystemMappingDto();
    systemMapping.setName("default_" + System.currentTimeMillis());
    systemMapping.setObjectClass(objectClass.getId());
    systemMapping.setOperationType(SystemOperationType.PROVISIONING);
    systemMapping.setEntityType(SystemEntityType.IDENTITY);
    systemMapping = systemMappingService.save(systemMapping);
    SysSystemMappingFilter entityHandlingFilter = new SysSystemMappingFilter();
    entityHandlingFilter.setSystemId(system.getId());
    // schema attribute handling
    SysSystemAttributeMappingDto schemaAttributeHandling = new SysSystemAttributeMappingDto();
    schemaAttributeHandling.setSchemaAttribute(schemaAttribute.getId());
    schemaAttributeHandling.setSystemMapping(systemMapping.getId());
    schemaAttributeHandling.setName("name");
    schemaAttributeHandling.setIdmPropertyName("name");
    schemaAttributeHandling = systemAttributeMappingService.save(schemaAttributeHandling);
    SysSystemAttributeMappingFilter schemaAttributeHandlingFilter = new SysSystemAttributeMappingFilter();
    schemaAttributeHandlingFilter.setSystemId(system.getId());
    // role system
    IdmRoleDto role = helper.createRole();
    SysRoleSystemDto roleSystem = new SysRoleSystemDto();
    roleSystem.setSystem(system.getId());
    roleSystem.setRole(role.getId());
    roleSystem.setSystemMapping(systemMapping.getId());
    roleSystem = roleSystemService.save(roleSystem);
    SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
    roleSystemFilter.setRoleId(role.getId());
    // role system attributes
    SysRoleSystemAttributeDto roleSystemAttribute = new SysRoleSystemAttributeDto();
    roleSystemAttribute.setRoleSystem(roleSystem.getId());
    roleSystemAttribute.setSystemAttributeMapping(schemaAttributeHandling.getId());
    roleSystemAttribute.setName("name");
    roleSystemAttribute.setIdmPropertyName("name");
    roleSystemAttribute = roleSystemAttributeService.save(roleSystemAttribute);
    assertEquals(systemName, systemService.getByCode(systemName).getName());
    assertEquals(1, schemaObjectClassService.find(objectClassFilter, null).getTotalElements());
    assertEquals(1, schemaAttributeService.find(schemaAttributeFilter, null).getTotalElements());
    assertEquals(1, systemMappingService.find(entityHandlingFilter, null).getTotalElements());
    assertEquals(1, systemAttributeMappingService.find(schemaAttributeHandlingFilter, null).getTotalElements());
    assertEquals(1, roleSystemService.find(roleSystemFilter, null).getTotalElements());
    assertNotNull(roleSystemAttributeService.get(roleSystemAttribute.getId()));
    systemService.delete(system);
    assertNull(systemService.getByCode(systemName));
    assertEquals(0, schemaObjectClassService.find(objectClassFilter, null).getTotalElements());
    assertEquals(0, schemaAttributeService.find(schemaAttributeFilter, null).getTotalElements());
    assertEquals(0, systemMappingService.find(entityHandlingFilter, null).getTotalElements());
    assertEquals(0, systemAttributeMappingService.find(schemaAttributeHandlingFilter, null).getTotalElements());
    assertEquals(0, roleSystemService.find(roleSystemFilter, null).getTotalElements());
    assertNull(roleSystemAttributeService.get(roleSystemAttribute.getId()));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 20 with SysSystemAttributeMappingFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter in project CzechIdMng by bcvsolutions.

the class IdentitySyncTest method testSynchronizationCache.

@Test
public void testSynchronizationCache() {
    SysSystemDto system = initData();
    SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
    IdmRoleDto defaultRole = helper.createRole();
    // Set default role to sync configuration
    config.setDefaultRole(defaultRole.getId());
    config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
    this.getBean().deleteAllResourceData();
    String testLastName = "test-last-name-same-" + System.currentTimeMillis();
    String testFirstName = "test-first-name";
    String userOne = "test-1-" + System.currentTimeMillis();
    this.getBean().setTestData(userOne, testFirstName, testLastName);
    String userTwo = "test-2-" + System.currentTimeMillis();
    this.getBean().setTestData(userTwo, testFirstName, testLastName);
    SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
    mappingFilter.setEntityType(SystemEntityType.IDENTITY);
    mappingFilter.setSystemId(system.getId());
    mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
    List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent();
    Assert.assertEquals(1, mappings.size());
    SysSystemMappingDto defaultMapping = mappings.get(0);
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemMappingId(defaultMapping.getId());
    List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
    SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
        return attribute.getIdmPropertyName().equals(IdmIdentity_.firstName.getName());
    }).findFirst().orElse(null);
    Assert.assertNotNull(firstNameAttribute);
    StringBuilder scriptGenerateUuid = new StringBuilder();
    scriptGenerateUuid.append("import java.util.UUID;");
    scriptGenerateUuid.append(System.lineSeparator());
    scriptGenerateUuid.append("return UUID.randomUUID();");
    String scriptName = "generateUuid";
    IdmScriptDto scriptUuid = new IdmScriptDto();
    scriptUuid.setCategory(IdmScriptCategory.TRANSFORM_FROM);
    scriptUuid.setCode(scriptName);
    scriptUuid.setName(scriptName);
    scriptUuid.setScript(scriptGenerateUuid.toString());
    scriptUuid = scriptService.save(scriptUuid);
    IdmScriptAuthorityDto scriptAuth = new IdmScriptAuthorityDto();
    scriptAuth.setClassName("java.util.UUID");
    scriptAuth.setType(ScriptAuthorityType.CLASS_NAME);
    scriptAuth.setScript(scriptUuid.getId());
    scriptAuth = scriptAuthrotityService.save(scriptAuth);
    // we must call script
    StringBuilder transformationScript = new StringBuilder();
    transformationScript.append("return scriptEvaluator.evaluate(");
    transformationScript.append(System.lineSeparator());
    transformationScript.append("scriptEvaluator.newBuilder()");
    transformationScript.append(System.lineSeparator());
    transformationScript.append(".setScriptCode('" + scriptName + "')");
    transformationScript.append(System.lineSeparator());
    transformationScript.append(".build());");
    transformationScript.append(System.lineSeparator());
    firstNameAttribute.setTransformFromResourceScript(transformationScript.toString());
    firstNameAttribute.setCached(true);
    firstNameAttribute = schemaAttributeMappingService.save(firstNameAttribute);
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.WARNING);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    IdmIdentityFilter filter = new IdmIdentityFilter();
    filter.setLastName(testLastName);
    List<IdmIdentityDto> identities = identityService.find(filter, null).getContent();
    assertEquals(2, identities.size());
    // 
    IdmIdentityDto identityOne = identities.get(0);
    IdmIdentityDto identityTwo = identities.get(1);
    // 
    assertNotEquals(identityOne.getFirstName(), identityTwo.getFirstName());
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) DefaultSynchronizationServiceTest(eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)

Aggregations

SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)35 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)31 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)26 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)23 Test (org.junit.Test)23 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)18 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)12 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)11 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)11 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)10 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)10 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)10 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)9 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)7 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)7 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)6 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)5 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)5