Search in sources :

Example 1 with SysSystemAttributeMapping_

use of eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_ in project CzechIdMng by bcvsolutions.

the class PrepareConnectorObjectProcessor method processCreate.

/**
 * Create object on target system
 *
 * @param provisioningOperation
 */
private void processCreate(SysProvisioningOperationDto provisioningOperation) {
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    ProvisioningContext provisioningContext = provisioningOperation.getProvisioningContext();
    IcConnectorObject connectorObject = provisioningContext.getConnectorObject();
    // 
    // prepare provisioning attributes from account attributes
    Map<ProvisioningAttributeDto, Object> fullAccountObject = provisioningOperationService.getFullAccountObject(provisioningOperation);
    if (fullAccountObject != null) {
        connectorObject.getAttributes().clear();
        SysSystemMappingDto mapping = getMapping(system, provisioningOperation.getEntityType());
        SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
        List<SysSchemaAttributeDto> schemaAttributes = findSchemaAttributes(system, schemaObjectClassDto);
        List<SysSystemAttributeMappingDto> passwordAttributes = attributeMappingService.getAllPasswordAttributes(system.getId(), mapping.getId());
        GuardedString generatedPassword = null;
        // If exists at least one password attribute generate password and try set echos for current system
        if (!passwordAttributes.isEmpty()) {
            // Check if exists a uniform password for this entity. If yes, then use it.
            if (provisioningOperation.getEntityIdentifier() != null && provisioningOperation.getEntityType() != null && provisioningOperation.getSystem() != null && provisioningOperation.getTransactionId() != null) {
                if (uniformPasswordManager.isSystemInUniformPasswordAgenda(provisioningOperation.getSystem())) {
                    generatedPassword = uniformPasswordManager.generateUniformPassword(provisioningOperation.getEntityIdentifier(), provisioningOperation.getEntityType().getEntityType(), provisioningOperation.getTransactionId());
                }
            }
            if (generatedPassword == null) {
                generatedPassword = generatePassword(system);
            }
        } else {
            generatedPassword = null;
        }
        // Found all given password from original provisioning context, these passwords will be skipped
        List<ProvisioningAttributeDto> givenPasswords = provisioningContext.getAccountObject().keySet().stream().filter(provisioningAtt -> provisioningAtt.isPasswordAttribute()).collect(Collectors.toList());
        // Iterate over all password attributes founded for system and mapping
        for (SysSystemAttributeMappingDto passwordAttribute : passwordAttributes) {
            // Password may be add by another process or execute existing provisioning operation, these password skip
            SysSchemaAttributeDto schemaByPasswordAttribute = DtoUtils.getEmbedded(passwordAttribute, SysSystemAttributeMapping_.schemaAttribute, SysSchemaAttributeDto.class);
            Optional<ProvisioningAttributeDto> findAnyPassword = // 
            givenPasswords.stream().filter(givenPassword -> givenPassword.getSchemaAttributeName().equals(// 
            schemaByPasswordAttribute.getName())).findAny();
            if (findAnyPassword.isPresent()) {
                continue;
            }
            // All non existing passwords in provisioning context will be added and
            // transformed. Then will be set as new attribute into fullAccountObject
            GuardedString transformPassword = transformPassword(provisioningOperation, system.getId(), passwordAttribute, generatedPassword);
            SysSchemaAttributeDto schemaAttribute = // 
            schemaAttributes.stream().filter(// 
            schemaAtt -> schemaAtt.getId().equals(passwordAttribute.getSchemaAttribute())).findFirst().orElse(null);
            ProvisioningAttributeDto passwordProvisiongAttributeDto = ProvisioningAttributeDto.createProvisioningAttributeKey(passwordAttribute, schemaAttribute.getName(), schemaAttribute.getClassType());
            fullAccountObject.put(passwordProvisiongAttributeDto, transformPassword);
            // Update previous account object (gui left side)
            Map<ProvisioningAttributeDto, Object> accountObject = provisioningOperation.getProvisioningContext().getAccountObject();
            // Is needed put password also into account object. Complete provisioning operation can be stored in
            // queue and while retry the provisioning operation is value get from confidential storage.
            // Confidential key is composed by account object.
            String confidentialStrorageKey = provisioningOperationService.createAccountObjectPropertyKey(passwordProvisiongAttributeDto.getKey(), 0);
            confidentialStorage.saveGuardedString(provisioningOperation, confidentialStrorageKey, transformPassword);
            accountObject.put(passwordProvisiongAttributeDto, new ConfidentialString(confidentialStrorageKey));
        }
        for (Entry<ProvisioningAttributeDto, Object> entry : fullAccountObject.entrySet()) {
            ProvisioningAttributeDto provisioningAttribute = entry.getKey();
            Optional<SysSchemaAttributeDto> schemaAttributeOptional = schemaAttributes.stream().filter(schemaAttribute -> {
                return provisioningAttribute.getSchemaAttributeName().equals(schemaAttribute.getName());
            }).findFirst();
            if (!schemaAttributeOptional.isPresent()) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_SCHEMA_ATTRIBUTE_IS_FOUND, ImmutableMap.of("attribute", provisioningAttribute.getSchemaAttributeName()));
            }
            Object idmValue = fullAccountObject.get(provisioningAttribute);
            SysSchemaAttributeDto schemaAttribute = schemaAttributeOptional.get();
            if (provisioningAttribute.isSendOnlyIfNotNull()) {
                if (this.isValueEmpty(idmValue)) {
                    // is null
                    continue;
                }
            }
            if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType() || AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
                boolean existSetAttribute = // 
                fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
                    // 
                    return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.SET == provisioningAttributeKey.getStrategyType();
                });
                boolean existIfResourceNulltAttribute = // 
                fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
                    // 
                    return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttributeKey.getStrategyType();
                });
                boolean existMergeAttribute = // 
                fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
                    // 
                    return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.MERGE == provisioningAttributeKey.getStrategyType();
                });
                boolean existAuthMergeAttribute = // 
                fullAccountObject.keySet().stream().anyMatch(provisioningAttributeKey -> {
                    return provisioningAttributeKey.getSchemaAttributeName().equals(schemaAttribute.getName()) && AttributeMappingStrategyType.AUTHORITATIVE_MERGE == provisioningAttributeKey.getStrategyType();
                });
                if (AttributeMappingStrategyType.CREATE == provisioningAttribute.getStrategyType()) {
                    if (existIfResourceNulltAttribute || existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
                        // (this strategies has higher priority)
                        continue;
                    }
                }
                if (AttributeMappingStrategyType.WRITE_IF_NULL == provisioningAttribute.getStrategyType()) {
                    if (existSetAttribute || existAuthMergeAttribute || existMergeAttribute) {
                        // (this strategies has higher priority)
                        continue;
                    }
                }
            }
            IcAttribute createdAttribute = createAttribute(schemaAttribute, fullAccountObject.get(provisioningAttribute));
            if (createdAttribute != null) {
                connectorObject.getAttributes().add(createdAttribute);
            }
        }
        provisioningContext.setConnectorObject(connectorObject);
    }
    provisioningOperation.setOperationType(ProvisioningEventType.CREATE);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSystemAttributeMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) SysSchemaAttribute(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ProvisioningConfiguration(eu.bcvsolutions.idm.acc.config.domain.ProvisioningConfiguration) SysProvisioningAttributeService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningAttributeService) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) ImmutableMap(com.google.common.collect.ImmutableMap) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) UniformPasswordManager(eu.bcvsolutions.idm.acc.service.api.UniformPasswordManager) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) Collection(java.util.Collection) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) Set(java.util.Set) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) ConnectorManager(eu.bcvsolutions.idm.acc.service.api.ConnectorManager) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) CollectionUtils(org.springframework.util.CollectionUtils) Entry(java.util.Map.Entry) Optional(java.util.Optional) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MessageFormat(java.text.MessageFormat) Strings(com.google.common.base.Strings) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) Description(org.springframework.context.annotation.Description) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) IdmPasswordPolicyType(eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) Component(org.springframework.stereotype.Component) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) IdmPasswordPolicyService(eu.bcvsolutions.idm.core.api.service.IdmPasswordPolicyService) Assert(org.springframework.util.Assert) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 2 with SysSystemAttributeMapping_

use of eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_ in project CzechIdMng by bcvsolutions.

the class AttributeControlledValuesRecalculationTaskExecutor method process.

@Override
public Boolean process() {
    this.counter = 0L;
    SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(systemId, entityType);
    Assert.notNull(mapping, "Provisioning mapping is mandatory!");
    // Loading all attributes for recalculation (on given system)
    SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
    attributeFilter.setSystemId(systemId);
    attributeFilter.setSystemMappingId(mapping.getId());
    List<SysSystemAttributeMappingDto> attributes = // 
    systemAttributeMappingService.find(attributeFilter, null).getContent().stream().filter(// 
    attribute -> AttributeMappingStrategyType.MERGE == attribute.getStrategyType()).filter(// 
    attribute -> !onlyEvicted ? true : attribute.isEvictControlledValuesCache()).collect(Collectors.toList());
    // Total items
    count = Long.valueOf(attributes.size());
    for (SysSystemAttributeMappingDto attribute : attributes) {
        counter++;
        boolean canContinue = updateState();
        if (!canContinue) {
            break;
        }
        try {
            SysSchemaAttributeDto schemaAttributeDto = DtoUtils.getEmbedded(attribute, SysSystemAttributeMapping_.schemaAttribute, SysSchemaAttributeDto.class);
            // Recalculate controlled values
            systemAttributeMappingService.recalculateAttributeControlledValues(systemId, entityType, schemaAttributeDto.getName(), attribute);
            // Success
            this.logItemProcessed(attribute, new OperationResult.Builder(OperationState.EXECUTED).build());
        } catch (Exception ex) {
            this.logItemProcessed(attribute, new OperationResult.Builder(OperationState.EXCEPTION).setException(new ResultCodeException(AccResultCode.PROVISIONING_EX_ATTR_CONTROLED_VALUE_RECALC, ImmutableMap.of("attribute", attribute.getName(), "system", systemId), ex)).build());
        }
    }
    ;
    LOG.info("End: Merge - attribute controlled values recalculation for system [{}]", systemId);
    return Boolean.TRUE;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AccFaceType(eu.bcvsolutions.idm.acc.eav.domain.AccFaceType) SysSystemAttributeMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) Lists(com.google.common.collect.Lists) AbstractSchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractSchedulableTaskExecutor) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) DisallowConcurrentExecution(org.quartz.DisallowConcurrentExecution) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) List(java.util.List) Component(org.springframework.stereotype.Component) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)2 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)2 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)2 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)2 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)2 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)2 SysSystemAttributeMapping_ (eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_)2 SysSystemAttributeMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService)2 SysSystemMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService)2 Strings (com.google.common.base.Strings)1 AccModuleDescriptor (eu.bcvsolutions.idm.acc.AccModuleDescriptor)1 ProvisioningConfiguration (eu.bcvsolutions.idm.acc.config.domain.ProvisioningConfiguration)1 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)1 ProvisioningEventType (eu.bcvsolutions.idm.acc.domain.ProvisioningEventType)1 SystemOperationType (eu.bcvsolutions.idm.acc.domain.SystemOperationType)1 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)1 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)1 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)1