Search in sources :

Example 1 with MappingContext

use of eu.bcvsolutions.idm.acc.domain.MappingContext in project CzechIdMng by bcvsolutions.

the class AbstractProvisioningExecutor method prepareProvisioning.

private SysProvisioningOperationDto prepareProvisioning(SysSystemEntityDto systemEntity, DTO dto, UUID entityId, ProvisioningOperationType operationType, List<? extends AttributeMapping> attributes) {
    Assert.notNull(systemEntity, "System entity is required.");
    Assert.notNull(systemEntity.getUid(), "System entity uid is required.");
    Assert.notNull(systemEntity.getEntityType(), "System entity type is required.");
    SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system);
    // If are input attributes null, then we load default mapped attributes
    if (attributes == null) {
        attributes = findAttributeMappings(system, systemEntity.getEntityType());
    }
    if (attributes == null || attributes.isEmpty()) {
        return null;
    }
    // One IDM object can be mapped to one connector object (= one connector
    // class).
    SysSystemMappingDto mapping = getMapping(system, systemEntity.getEntityType());
    if (mapping == null) {
        // TODO: delete operation?
        return null;
    }
    // Create mapping context from the script defined on the mapping and by checked options.
    // This context will be propagate to all attributes (transformation to the system).
    MappingContext mappingContext = systemMappingService.getMappingContext(mapping, systemEntity, dto, system);
    Map<ProvisioningAttributeDto, Object> accountAttributes = prepareMappedAttributesValues(dto, operationType, systemEntity, attributes, mappingContext);
    UUID roleRequestId = null;
    if (ProvisioningOperationType.DELETE == operationType) {
        // Return ID of role-request from system-entity's context.
        roleRequestId = getRoleRequestIdFromContext(systemEntity);
    } else {
        // Return ID of role-request from DTO's context.
        roleRequestId = getRoleRequestIdFromContext(dto);
    }
    // public provisioning event
    SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    IcConnectorObject connectorObject = new IcConnectorObjectImpl(systemEntity.getUid(), new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName()), null);
    // Propagate the role-request ID to the connector (for virtual systems ...)
    connectorObject.getObjectClass().setRoleRequestId(roleRequestId);
    SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(// 
    operationType).setSystemEntity(// 
    systemEntity).setEntityIdentifier(// 
    entityId).setRoleRequestId(roleRequestId).setProvisioningContext(new ProvisioningContext(accountAttributes, connectorObject));
    // 
    return operationBuilder.build();
}
Also used : IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 2 with MappingContext

use of eu.bcvsolutions.idm.acc.domain.MappingContext in project CzechIdMng by bcvsolutions.

the class MappingContextTest method testMappingContextIdentityRolesForSystem.

@Test
public void testMappingContextIdentityRolesForSystem() {
    SysSystemDto system = helper.createTestResourceSystem(true);
    Assert.assertNotNull(system);
    SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
    Assert.assertNotNull(mapping);
    // Create the description attribute (print context as string).
    createDescriptionAttribute(system, mapping);
    // Set context transformation to the mapping.
    // Add identity roles for this system to the context.
    mapping.setAddContextIdentityRolesForSystem(true);
    mapping = initContextForMapping(mapping);
    IdmRoleDto roleWithSystem = helper.createRole();
    IdmRoleDto roleWithoutSystem = helper.createRole();
    helper.createRoleSystem(roleWithSystem, system);
    IdmIdentityDto identity = helper.createIdentity();
    helper.createIdentityRole(identity, roleWithoutSystem, null, null);
    IdmIdentityRoleDto identityRoleWithSystem = helper.createIdentityRole(identity, roleWithSystem, null, null);
    IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
    identityRoleFilter.setIdentityId(identity.getId());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
    Assert.assertEquals(2, identityRoles.size());
    TestResource resource = helper.findResource(identity.getUsername());
    assertNotNull(resource);
    assertEquals(identity.getFirstName(), resource.getFirstname());
    MappingContext context = new MappingContext();
    context.put("test", "TestValueOne");
    context.setIdentityRolesForSystem(Lists.newArrayList(identityRoleWithSystem));
    assertEquals(context.toString(), resource.getDescrip());
    // Delete role mapping
    systemMappingService.delete(mapping);
}
Also used : MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with MappingContext

use of eu.bcvsolutions.idm.acc.domain.MappingContext in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemAttributeMappingService method getAttributeValue.

/**
 * Find value for this mapped attribute by property name. Returned value can be
 * list of objects. Returns transformed value.
 *
 * @param uid               - Account identifier
 * @param entity
 * @param attributeHandling
 * @return
 * @throws IntrospectionException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
@Override
public Object getAttributeValue(String uid, AbstractDto entity, AttributeMapping attributeHandling, MappingContext mappingContext) {
    Object idmValue = null;
    // 
    if (attributeHandling.isPasswordAttribute()) {
        // there but in PrepareConnectorObjectProcessor
        return null;
    }
    // 
    SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeHandling);
    // 
    if (attributeHandling.isExtendedAttribute() && entity != null && formService.isFormable(entity.getClass())) {
        List<IdmFormValueDto> formValues = formService.getValues(entity, attributeHandling.getIdmPropertyName());
        if (formValues.isEmpty()) {
            idmValue = null;
        } else if (schemaAttributeDto.isMultivalued()) {
            // Multiple value extended attribute
            List<Object> values = new ArrayList<>();
            formValues.stream().forEachOrdered(formValue -> {
                values.add(this.resolveFormValue(formValue));
            });
            idmValue = values;
        } else {
            // Single value extended attribute
            IdmFormValueDto formValue = formValues.get(0);
            if (formValue.isConfidential()) {
                Object confidentialValue = formService.getConfidentialPersistentValue(formValue);
                // then convert to GuardedString will be did.
                if (confidentialValue instanceof String && schemaAttributeDto.getClassType().equals(GuardedString.class.getName())) {
                    idmValue = new GuardedString((String) confidentialValue);
                } else {
                    idmValue = confidentialValue;
                }
            } else {
                idmValue = this.resolveFormValue(formValue);
            }
        }
    } else // Find value from entity
    if (attributeHandling.isEntityAttribute()) {
        if (attributeHandling.isConfidentialAttribute()) {
            // If is attribute isConfidential, then we will find value in
            // secured storage
            idmValue = confidentialStorage.getGuardedString(entity.getId(), entity.getClass(), attributeHandling.getIdmPropertyName());
        } else {
            try {
                // We will search value directly in entity by property name
                idmValue = EntityUtils.getEntityValue(entity, attributeHandling.getIdmPropertyName());
            } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException ex) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_IDM_FIELD_NOT_FOUND, ImmutableMap.of("property", attributeHandling.getIdmPropertyName(), "entityType", entity.getClass(), "schemaAtribute", attributeHandling.getSchemaAttribute().toString()), ex);
            }
        }
    } else {
    // If Attribute value is not in entity nor in extended attribute, then idmValue
    // is null.
    // It means attribute is static ... we will call transformation to resource.
    }
    return this.transformValueToResource(uid, idmValue, attributeHandling, entity, mappingContext);
}
Also used : IdmScriptCategory(eu.bcvsolutions.idm.core.api.domain.IdmScriptCategory) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) PluginRegistry(org.springframework.plugin.core.PluginRegistry) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SysSystemAttributeMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) SysSchemaAttribute(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOUtils(org.apache.commons.io.IOUtils) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) SysSyncConfigRepository(eu.bcvsolutions.idm.acc.repository.SysSyncConfigRepository) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) SysSystemMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemMapping_) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) BooleanUtils(org.apache.commons.lang3.BooleanUtils) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Root(javax.persistence.criteria.Root) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) AbstractScriptEvaluator(eu.bcvsolutions.idm.core.script.evaluator.AbstractScriptEvaluator) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) Subquery(javax.persistence.criteria.Subquery) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) SysSystemAttributeMappingRepository(eu.bcvsolutions.idm.acc.repository.SysSystemAttributeMappingRepository) FormPropertyManager(eu.bcvsolutions.idm.acc.service.api.FormPropertyManager) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SysSchemaAttribute_(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute_) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) SysSchemaObjectClass(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) ImmutableMap(com.google.common.collect.ImmutableMap) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) SysRoleSystemAttributeRepository(eu.bcvsolutions.idm.acc.repository.SysRoleSystemAttributeRepository) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Optional(java.util.Optional) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) OrderAwarePluginRegistry(org.springframework.plugin.core.OrderAwarePluginRegistry) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) IcPasswordAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcPasswordAttributeImpl) HashMap(java.util.HashMap) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttribute_(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_) IdmAttachmentWithDataDto(eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto) MessageFormat(java.text.MessageFormat) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) SysSystemMapping(eu.bcvsolutions.idm.acc.entity.SysSystemMapping) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) SysSystemGroupSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemGroupSystemService) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) SysAttributeControlledValueService(eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService) SysSyncRoleConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncRoleConfig_) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ArrayList(java.util.ArrayList) List(java.util.List) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Example 4 with MappingContext

use of eu.bcvsolutions.idm.acc.domain.MappingContext 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 5 with MappingContext

use of eu.bcvsolutions.idm.acc.domain.MappingContext in project CzechIdMng by bcvsolutions.

the class MappingContextTest method testMappingContextContract.

@Test
public void testMappingContextContract() {
    SysSystemDto system = helper.createTestResourceSystem(true);
    Assert.assertNotNull(system);
    SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
    Assert.assertNotNull(mapping);
    // Create the description attribute (print context as string).
    createDescriptionAttribute(system, mapping);
    // Set context transformation to the mapping
    // Add identity contracts to the context.
    mapping.setAddContextContracts(true);
    mapping = initContextForMapping(mapping);
    IdmRoleDto roleWithSystem = helper.createRole();
    helper.createRoleSystem(roleWithSystem, system);
    IdmIdentityDto identity = helper.createIdentity();
    helper.createContract(identity, null, LocalDate.now(), null);
    List<IdmIdentityContractDto> contracts = identityContractService.findAllByIdentity(identity.getId());
    Assert.assertEquals(2, contracts.size());
    helper.createIdentityRole(identity, roleWithSystem, null, null);
    TestResource resource = helper.findResource(identity.getUsername());
    assertNotNull(resource);
    assertEquals(identity.getFirstName(), resource.getFirstname());
    MappingContext context = new MappingContext();
    context.put("test", "TestValueOne");
    context.setContracts(contracts);
    assertEquals(context.toString(), resource.getDescrip());
    // Delete role mapping
    systemMappingService.delete(mapping);
}
Also used : MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

MappingContext (eu.bcvsolutions.idm.acc.domain.MappingContext)9 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)8 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 Test (org.junit.Test)4 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)3 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)2 AttributeMapping (eu.bcvsolutions.idm.acc.domain.AttributeMapping)2 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)2 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)2 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)2 SystemOperationType (eu.bcvsolutions.idm.acc.domain.SystemOperationType)2 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)2 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)2 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)2