Search in sources :

Example 16 with SysProvisioningOperationDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto 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);
    Assert.notNull(systemEntity.getUid());
    Assert.notNull(systemEntity.getEntityType());
    SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system, SysSystemDto.class);
    Assert.notNull(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;
    }
    // Find connector identification persisted in system
    IcConnectorKey connectorKey = system.getConnectorKey();
    if (connectorKey == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // Find connector configuration persisted in system
    IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
    if (connectorConfig == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // 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;
    }
    // 
    Map<ProvisioningAttributeDto, Object> accountAttributes = prepareMappedAttributesValues(dto, operationType, systemEntity, attributes);
    // public provisioning event
    SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    IcConnectorObject connectorObject = new IcConnectorObjectImpl(systemEntity.getUid(), new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName()), null);
    SysProvisioningOperationDto.Builder operationBuilder = new SysProvisioningOperationDto.Builder().setOperationType(operationType).setSystemEntity(systemEntity).setEntityIdentifier(entityId).setProvisioningContext(new ProvisioningContext(accountAttributes, connectorObject));
    // 
    return operationBuilder.build();
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) 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) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 17 with SysProvisioningOperationDto

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

the class DefaultProvisioningExecutor method execute.

@Override
public OperationResult execute(SysProvisioningBatchDto batch) {
    Assert.notNull(batch);
    batch = batchService.get(batch.getId());
    // 
    OperationResult result = null;
    for (SysProvisioningOperationDto provisioningOperation : provisioningOperationService.getByTimelineAndBatchId(batch.getId())) {
        // It not possible to get operation from embedded, because missing request
        // not run in transaction
        SysProvisioningOperationDto operation = executeInternal(provisioningOperation);
        result = operation.getResult();
        if (OperationState.EXECUTED != result.getState()) {
            // stop processing next requests
            return result;
        }
    }
    // last processed request state (previous requests will be OperationState.EXECUTED)
    return result;
}
Also used : OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 18 with SysProvisioningOperationDto

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

the class DefaultSysProvisioningOperationService method getFullAccountObject.

/**
 * Returns fully loaded AccountObject with guarded strings.
 *
 * @param provisioningOperation
 * @return
 */
@Override
public Map<ProvisioningAttributeDto, Object> getFullAccountObject(SysProvisioningOperationDto provisioningOperation) {
    if (provisioningOperation == null || provisioningOperation.getProvisioningContext() == null || provisioningOperation.getProvisioningContext().getAccountObject() == null) {
        return null;
    }
    // 
    Map<ProvisioningAttributeDto, Object> fullAccountObject = new HashMap<>();
    Map<ProvisioningAttributeDto, Object> accountObject = provisioningOperation.getProvisioningContext().getAccountObject();
    for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
        if (entry.getValue() == null) {
            fullAccountObject.put(entry.getKey(), entry.getValue());
            continue;
        }
        Object idmValue = entry.getValue();
        // single value
        if (idmValue instanceof ConfidentialString) {
            fullAccountObject.put(entry.getKey(), confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) idmValue).getKey()));
            continue;
        }
        // array
        if (idmValue.getClass().isArray()) {
            if (!idmValue.getClass().getComponentType().isPrimitive()) {
                // objects only, we dont want pto proces byte, boolean etc.
                Object[] idmValues = (Object[]) idmValue;
                List<GuardedString> processedValues = new ArrayList<>();
                for (int j = 0; j < idmValues.length; j++) {
                    Object singleValue = idmValues[j];
                    if (singleValue instanceof ConfidentialString) {
                        processedValues.add(confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey()));
                    }
                }
                if (!processedValues.isEmpty()) {
                    fullAccountObject.put(entry.getKey(), processedValues.toArray(new GuardedString[processedValues.size()]));
                    continue;
                }
            }
        } else // collection
        if (idmValue instanceof Collection) {
            Collection<?> idmValues = (Collection<?>) idmValue;
            List<GuardedString> processedValues = new ArrayList<>();
            idmValues.forEach(singleValue -> {
                if (singleValue instanceof ConfidentialString) {
                    processedValues.add(confidentialStorage.getGuardedString(provisioningOperation.getId(), SysProvisioningOperation.class, ((ConfidentialString) singleValue).getKey()));
                }
            });
            if (!processedValues.isEmpty()) {
                fullAccountObject.put(entry.getKey(), processedValues);
                continue;
            }
        }
        // copy value
        fullAccountObject.put(entry.getKey(), entry.getValue());
    }
    return fullAccountObject;
}
Also used : NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) IcPasswordAttribute(eu.bcvsolutions.idm.ic.api.IcPasswordAttribute) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) PageRequest(org.springframework.data.domain.PageRequest) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Serializable(java.io.Serializable) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Entry(java.util.Map.Entry) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IcPasswordAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcPasswordAttributeImpl) HashMap(java.util.HashMap) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SysProvisioningOperationRepository(eu.bcvsolutions.idm.acc.repository.SysProvisioningOperationRepository) ArrayList(java.util.ArrayList) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) Service(org.springframework.stereotype.Service) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) Direction(org.springframework.data.domain.Sort.Direction) SysProvisioningOperation_(eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation_) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) SysProvisioningOperation(eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysProvisioningBatchService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningBatchService) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) Collections(java.util.Collections) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysProvisioningOperation(eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) Collection(java.util.Collection) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with SysProvisioningOperationDto

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

the class DefaultSysProvisioningOperationService method handleFailed.

@Override
@Transactional
public SysProvisioningOperationDto handleFailed(SysProvisioningOperationDto operation, Exception ex) {
    SysSystemDto system = systemService.get(operation.getSystem());
    String uid = this.getByProvisioningOperation(operation).getUid();
    ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
    LOG.error(resultModel.toString(), ex);
    // 
    operation.increaseAttempt();
    // TODO: from configuration
    operation.setMaxAttempts(6);
    operation.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setCode(resultModel.getStatusEnum()).setModel(resultModel).setCause(ex).build());
    // 
    operation = save(operation);
    // 
    // calculate next attempt
    SysProvisioningOperationDto firstOperation = getFirstOperationByBatchId(operation.getBatch());
    if (firstOperation.equals(operation)) {
        SysProvisioningBatchDto batch = batchService.get(operation.getBatch());
        batch.setNextAttempt(batchService.calculateNextAttempt(operation));
        batch = batchService.save(batch);
    }
    // 
    if (securityService.getCurrentId() != null) {
        // TODO: check account owner
        notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
    }
    return operation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with SysProvisioningOperationDto

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

the class DefaultSysSystemServiceTest method testReferentialIntegrityProvisioningOperationExists.

@Test(expected = ResultCodeException.class)
public void testReferentialIntegrityProvisioningOperationExists() {
    SysSystemDto system = new SysSystemDto();
    String systemName = "t_s_" + System.currentTimeMillis();
    system.setName(systemName);
    system = systemService.save(system);
    // system entity
    SysSystemEntityDto systemEntity = new SysSystemEntityDto();
    systemEntity.setUid("test");
    systemEntity.setSystem(system.getId());
    systemEntity.setEntityType(SystemEntityType.IDENTITY);
    systemEntity = systemEntityService.save(systemEntity);
    SysProvisioningOperationDto provisioningOperation = new SysProvisioningOperationDto();
    provisioningOperation.setSystem(system.getId());
    provisioningOperation.setEntityType(SystemEntityType.IDENTITY);
    provisioningOperation.setOperationType(ProvisioningEventType.CREATE);
    provisioningOperation.setSystemEntity(systemEntity.getId());
    provisioningOperation.setEntityIdentifier(UUID.randomUUID());
    provisioningOperation.setProvisioningContext(new ProvisioningContext());
    provisioningOperation.setResult(new OperationResult());
    provisioningOperationService.save(provisioningOperation);
    // 
    systemService.delete(system);
}
Also used : ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)39 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)31 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)19 Test (org.junit.Test)19 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)17 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)16 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)16 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)13 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)12 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)11 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)10 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)10 SysProvisioningBatchDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)9 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)9 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)9 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)8 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)8 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)8 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)8 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)8