Search in sources :

Example 6 with MappingContext

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

the class MappingContextTest method testMappingContextConnectorObject.

@Test
public void testMappingContextConnectorObject() {
    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 connector object to the context.
    mapping.setAddContextConnectorObject(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");
    assertEquals(context.toString(), resource.getDescrip());
    SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
    IcConnectorObject connectorObject = systemEntityService.getConnectorObject(systemEntity);
    Assert.assertNotNull(connectorObject);
    // Invoke provisioning
    identityService.save(identity);
    resource = helper.findResource(identity.getUsername());
    assertNotNull(resource);
    assertEquals(identity.getFirstName(), resource.getFirstname());
    context = new MappingContext();
    context.put("test", "TestValueOne");
    context.setConnectorObject(connectorObject);
    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) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) 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)

Example 7 with MappingContext

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

the class MappingContextTest method testMappingContext.

@Test
public void testMappingContext() {
    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.
    mapping = initContextForMapping(mapping);
    IdmRoleDto roleWithSystem = helper.createRole();
    helper.createRoleSystem(roleWithSystem, system);
    IdmIdentityDto identity = helper.createIdentity();
    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");
    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) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with MappingContext

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

the class MappingContextTest method testMappingContextIdentityRoles.

@Test
public void testMappingContextIdentityRoles() {
    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 to the context.
    mapping.setAddContextIdentityRoles(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);
    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.setIdentityRoles(identityRoles);
    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) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with MappingContext

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

the class AbstractProvisioningExecutor method prepareMappedAttributesValues.

/**
 * Prepare all mapped attribute values (= account)
 *
 * @param dto
 * @param operationType
 * @param systemEntity
 * @param attributes
 * @return
 */
protected Map<ProvisioningAttributeDto, Object> prepareMappedAttributesValues(DTO dto, ProvisioningOperationType operationType, SysSystemEntityDto systemEntity, List<? extends AttributeMapping> attributes, MappingContext mappingContext) {
    AccAccountDto account = getAccountSystemEntity(systemEntity.getId());
    String uid = systemEntity.getUid();
    SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system);
    Map<ProvisioningAttributeDto, Object> accountAttributes = new HashMap<>();
    // delete - account attributes is not needed
    if (ProvisioningOperationType.DELETE == operationType) {
        return accountAttributes;
    }
    // First we will resolve attribute without MERGE strategy
    attributes.stream().filter(attribute -> {
        return !attribute.isDisabledAttribute() && !attribute.isPasswordAttribute() && AttributeMappingStrategyType.AUTHORITATIVE_MERGE != attribute.getStrategyType() && AttributeMappingStrategyType.MERGE != attribute.getStrategyType();
    }).forEach(attribute -> {
        SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attribute);
        if (attribute.isUid()) {
            // TODO: now we set UID from SystemEntity, may be UID from
            // AccAccount will be more correct
            Object uidValue = getAttributeValue(uid, dto, attribute, system, mappingContext);
            if (uidValue == null) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_GENERATED_UID_IS_NULL, ImmutableMap.of("system", system.getName()));
            }
            if (!(uidValue instanceof String)) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_ATTRIBUTE_UID_IS_NOT_STRING, ImmutableMap.of("uid", uidValue, "system", system.getName()));
            }
            updateAccountUid(account, uid, (String) uidValue);
            accountAttributes.put(ProvisioningAttributeDto.createProvisioningAttributeKey(attribute, schemaAttributeDto.getName(), schemaAttributeDto.getClassType()), uidValue);
        } else {
            accountAttributes.put(ProvisioningAttributeDto.createProvisioningAttributeKey(attribute, schemaAttributeDto.getName(), schemaAttributeDto.getClassType()), getAttributeValue(uid, dto, attribute, system, mappingContext));
        }
    });
    // Second we will resolve MERGE attributes
    List<? extends AttributeMapping> attributesMerge = attributes.stream().filter(attribute -> {
        return !attribute.isDisabledAttribute() && (AttributeMappingStrategyType.AUTHORITATIVE_MERGE == attribute.getStrategyType() || AttributeMappingStrategyType.MERGE == attribute.getStrategyType());
    }).collect(Collectors.toList());
    for (AttributeMapping attributeParent : attributesMerge) {
        SysSchemaAttributeDto schemaAttributeParent = getSchemaAttribute(attributeParent);
        ProvisioningAttributeDto attributeParentKey = ProvisioningAttributeDto.createProvisioningAttributeKey(attributeParent, schemaAttributeParent.getName(), schemaAttributeParent.getClassType());
        if (!schemaAttributeParent.isMultivalued()) {
            throw new ProvisioningException(AccResultCode.PROVISIONING_MERGE_ATTRIBUTE_IS_NOT_MULTIVALUE, ImmutableMap.of("object", uid, "attribute", schemaAttributeParent.getName(), "system", system.getName()));
        }
        // We use SET collection because we want collection of merged values without duplicates
        Set<Object> mergedValues = new LinkedHashSet<>();
        // 
        attributesMerge.stream().filter(attribute -> {
            // 
            SysSchemaAttributeDto schemaAttribute = getSchemaAttribute(attribute);
            return !accountAttributes.containsKey(attributeParentKey) && schemaAttributeParent.equals(schemaAttribute) && attributeParent.getStrategyType() == attribute.getStrategyType();
        }).forEach(attribute -> {
            Object value = getAttributeValue(uid, dto, attribute, system, mappingContext);
            // provisioning in IC)
            if (value != null) {
                // main list!
                if (value instanceof Collection) {
                    Collection<?> collectionNotNull = ((Collection<?>) value).stream().filter(item -> {
                        return item != null;
                    }).collect(Collectors.toList());
                    mergedValues.addAll(collectionNotNull);
                } else {
                    mergedValues.add(value);
                }
            }
        });
        if (!accountAttributes.containsKey(attributeParentKey)) {
            // we must put merged values as array list
            accountAttributes.put(attributeParentKey, new ArrayList<>(mergedValues));
        }
    }
    return accountAttributes;
}
Also used : ProvisioningExecutor(eu.bcvsolutions.idm.acc.service.api.ProvisioningExecutor) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) AccIdentityAccount_(eu.bcvsolutions.idm.acc.entity.AccIdentityAccount_) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) StringUtils(org.apache.commons.lang3.StringUtils) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSystemAttributeMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemEntity_(eu.bcvsolutions.idm.acc.entity.SysSystemEntity_) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ProvisioningEntityExecutor(eu.bcvsolutions.idm.acc.service.api.ProvisioningEntityExecutor) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) CollectionUtils(org.springframework.util.CollectionUtils) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) Optional(java.util.Optional) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ProvisioningEvent(eu.bcvsolutions.idm.acc.event.ProvisioningEvent) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttribute_(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SystemEntityNotFoundException(eu.bcvsolutions.idm.acc.exception.SystemEntityNotFoundException) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ImmutableList(com.google.common.collect.ImmutableList) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) ProvisioningOperationType(eu.bcvsolutions.idm.acc.domain.ProvisioningOperationType) LinkedHashSet(java.util.LinkedHashSet) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) Contextable(eu.bcvsolutions.idm.core.api.domain.Contextable) AccAccount_(eu.bcvsolutions.idm.acc.entity.AccAccount_) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) Collections(java.util.Collections) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Assert(org.springframework.util.Assert) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) Collection(java.util.Collection) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject)

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