Search in sources :

Example 16 with IcConnectorObject

use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestService method getWishConnectorObject.

@Override
public VsConnectorObjectDto getWishConnectorObject(VsRequestDto request) {
    LOG.info(MessageFormat.format("Start read wish connector object [{0}].", request));
    Assert.notNull(request, "VS request cannot be null!");
    List<VsAttributeDto> resultAttributes = new ArrayList<>();
    IcConnectorObject realConnectorObject = this.getVsConnectorObject(request);
    IcConnectorObject currentObject = realConnectorObject != null ? realConnectorObject : new IcConnectorObjectImpl();
    IcConnectorObject changeObject = request.getConnectorObject() != null ? request.getConnectorObject() : new IcConnectorObjectImpl();
    List<IcAttribute> currentAttributes = currentObject.getAttributes();
    List<IcAttribute> changedAttributes = request.getConnectorObject().getAttributes();
    // First add all new attributes
    changedAttributes.forEach(changedAttribute -> {
        if (currentObject.getAttributeByName(changedAttribute.getName()) == null) {
            VsAttributeDto vsAttribute = new VsAttributeDto(changedAttribute.getName(), changedAttribute.isMultiValue(), true);
            if (changedAttribute.isMultiValue()) {
                if (changedAttribute.getValues() != null) {
                    changedAttribute.getValues().forEach(value -> {
                        vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
                    });
                }
            } else {
                vsAttribute.setValue(new VsAttributeValueDto(changedAttribute.getValue(), null, VsValueChangeType.ADDED));
            }
            resultAttributes.add(vsAttribute);
        }
    });
    // Second add all already exists attributes
    currentAttributes.forEach(currentAttribute -> {
        VsAttributeDto vsAttribute;
        // Attribute was changed
        if (changeObject.getAttributeByName(currentAttribute.getName()) != null) {
            vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), true);
            IcAttribute changedAttribute = changeObject.getAttributeByName(currentAttribute.getName());
            if (changedAttribute.isMultiValue()) {
                if (changedAttribute.getValues() != null) {
                    changedAttribute.getValues().forEach(value -> {
                        if (currentAttribute.getValues() != null && currentAttribute.getValues().contains(value)) {
                            vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
                        } else {
                            vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
                        }
                    });
                }
                if (currentAttribute.getValues() != null) {
                    currentAttribute.getValues().forEach(value -> {
                        if (changedAttribute.getValues() == null || !changedAttribute.getValues().contains(value)) {
                            vsAttribute.getValues().add(new VsAttributeValueDto(value, value, VsValueChangeType.REMOVED));
                        }
                    });
                }
            } else {
                Object changedValue = changedAttribute.getValue();
                Object currentValue = currentAttribute.getValue();
                if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentObject)) || (currentValue != null && currentValue.equals(changedValue))) {
                    vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, null));
                } else {
                    vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, VsValueChangeType.UPDATED));
                }
            }
        } else {
            // Attribute was not changed
            vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), false);
            if (currentAttribute.isMultiValue()) {
                if (currentAttribute.getValues() != null) {
                    currentAttribute.getValues().forEach(value -> {
                        vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
                    });
                }
            } else {
                vsAttribute.setValue(new VsAttributeValueDto(currentAttribute.getValue(), currentAttribute.getValue(), null));
            }
        }
        resultAttributes.add(vsAttribute);
    });
    BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
    // result list
    if (!configuration.isDisableSupported()) {
        VsAttributeDto enableAttribute = resultAttributes.stream().filter(attribute -> attribute.getName().equals(IcAttributeInfo.ENABLE)).findFirst().orElse(null);
        if (enableAttribute != null) {
            resultAttributes.remove(enableAttribute);
        }
    }
    VsConnectorObjectDto wishObject = new VsConnectorObjectDto();
    wishObject.setUid(request.getUid());
    wishObject.setAttributes(resultAttributes);
    return wishObject;
}
Also used : VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ArrayList(java.util.ArrayList) VsAttributeValueDto(eu.bcvsolutions.idm.vs.dto.VsAttributeValueDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration)

Example 17 with IcConnectorObject

use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.

the class VsReqeustServiceTest method systemAccountFilterTest.

@Test
public void systemAccountFilterTest() {
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try realize the request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    request = requestService.realize(request);
    Assert.assertEquals(VsRequestState.REALIZED, request.getState());
    account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNotNull("Account cannot be null, because request was realized!", account);
    IcConnectorConfiguration configuration = systemService.getConnectorConfiguration(system);
    IcObjectClass objectClass = new IcObjectClassImpl("__ACCOUNT__");
    List<String> uids = new ArrayList<>();
    connectorFacade.search(system.getConnectorInstance(), configuration, objectClass, null, new IcResultsHandler() {

        @Override
        public boolean handle(IcConnectorObject connectorObject) {
            uids.add(connectorObject.getUidValue());
            return true;
        }
    });
    Assert.assertEquals(1, uids.size());
    Assert.assertEquals(USER_ONE_NAME, uids.get(0));
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 18 with IcConnectorObject

use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.

the class PrepareConnectorObjectProcessor method process.

/**
 * Prepare provisioning operation execution
 */
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    SysProvisioningOperationDto provisioningOperation = event.getContent();
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    IcObjectClass objectClass = provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass();
    SysSystemEntityDto systemEntity = provisioningOperationService.getByProvisioningOperation(provisioningOperation);
    String uid = systemEntity.getUid();
    boolean isWish = systemEntity.isWish();
    LOG.debug("Start preparing attribubes for provisioning operation [{}] for object with uid [{}] and connector object [{}]", provisioningOperation.getOperationType(), uid, objectClass.getType());
    // Find connector identification persisted in system
    if (system.getConnectorKey() == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // load connector configuration
    IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
    if (connectorConfig == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // 
    try {
        IcConnectorObject existsConnectorObject = null;
        // call the connector and auto mapping is not allowed.
        if (!(isWish && !provisioningConfiguration.isAllowedAutoMappingOnExistingAccount())) {
            IcUidAttribute uidAttribute = new IcUidAttributeImpl(null, uid, null);
            existsConnectorObject = connectorFacade.readObject(system.getConnectorInstance(), connectorConfig, objectClass, uidAttribute);
        }
        if (existsConnectorObject == null) {
            processCreate(provisioningOperation);
        } else {
            processUpdate(provisioningOperation, connectorConfig, existsConnectorObject);
        }
        // 
        LOG.debug("Preparing attribubes for provisioning operation [{}] for object with uid [{}] and connector object [{}] is sucessfully completed", provisioningOperation.getOperationType(), uid, objectClass.getType());
        // set back to event content
        provisioningOperation = provisioningOperationService.save(provisioningOperation);
        event.setContent(provisioningOperation);
        return new DefaultEventResult<>(event, this);
    } catch (Exception ex) {
        ResultModel resultModel;
        if (ex instanceof ResultCodeException) {
            resultModel = ((ResultCodeException) ex).getError().getError();
        } else {
            resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_PREPARE_ACCOUNT_ATTRIBUTES_FAILED, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", provisioningOperation.getOperationType(), "objectClass", objectClass.getType()));
        }
        LOG.error(resultModel.toString(), ex);
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
        // 
        provisioningOperation = provisioningOperationService.save(provisioningOperation);
        // 
        notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
        // set back to event content
        event.setContent(provisioningOperation);
        return new DefaultEventResult<>(event, this, true);
    }
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 19 with IcConnectorObject

use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.

the class PrepareConnectorObjectProcessor method updateAttribute.

/**
 * Update attribute on resource by given handling attribute and mapped value
 * in entity
 *
 * @param uid
 * @param entity
 * @param attributeMapping
 * @param schemaAttribute
 * @param connectorObject
 */
private IcAttribute updateAttribute(String uid, Object idmValue, SysSchemaAttributeDto schemaAttribute, IcConnectorObject existsConnectorObject, SysSystemDto system, ProvisioningAttributeDto provisioningAttributeDto) {
    List<IcAttribute> icAttributes = existsConnectorObject.getAttributes();
    // 
    Optional<IcAttribute> icAttributeOptional = icAttributes.stream().filter(ica -> {
        return schemaAttribute.getName().equals(ica.getName());
    }).findFirst();
    IcAttribute icAttribute = null;
    if (icAttributeOptional.isPresent()) {
        icAttribute = icAttributeOptional.get();
    }
    return updateAttributeValue(uid, idmValue, schemaAttribute, icAttribute, icAttributes, system, provisioningAttributeDto.getTransformValueFromResourceScript(), provisioningAttributeDto.isSendAlways());
}
Also used : SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSchemaAttribute(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ProvisioningConfiguration(eu.bcvsolutions.idm.acc.config.domain.ProvisioningConfiguration) Sort(org.springframework.data.domain.Sort) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) ImmutableMap(com.google.common.collect.ImmutableMap) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) Collection(java.util.Collection) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) PageRequest(org.springframework.data.domain.PageRequest) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) CollectionUtils(org.springframework.util.CollectionUtils) Entry(java.util.Map.Entry) Optional(java.util.Optional) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) 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) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) 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) Direction(org.springframework.data.domain.Sort.Direction) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) Description(org.springframework.context.annotation.Description) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) Component(org.springframework.stereotype.Component) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) Assert(org.springframework.util.Assert) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute)

Example 20 with IcConnectorObject

use of eu.bcvsolutions.idm.ic.api.IcConnectorObject in project CzechIdMng by bcvsolutions.

the class ProvisioningDeleteProcessor method processInternal.

@Override
public IcUidAttribute processInternal(SysProvisioningOperationDto provisioningOperation, IcConnectorConfiguration connectorConfig) {
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    IcConnectorInstance connectorInstance = systemService.getConnectorInstance(system);
    String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
    IcUidAttribute uidAttribute = new IcUidAttributeImpl(null, uid, null);
    IcObjectClass objectClass = provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass();
    // 
    IcConnectorObject connectorObject = connectorFacade.readObject(connectorInstance, connectorConfig, objectClass, uidAttribute);
    if (connectorObject != null) {
        connectorFacade.deleteObject(connectorInstance, connectorConfig, objectClass, uidAttribute);
    }
    return null;
}
Also used : IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)39 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)21 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)17 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)13 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)12 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)12 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)11 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)11 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)10 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)10 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)9 ArrayList (java.util.ArrayList)9 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)8 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)8 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)8 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)8 Test (org.junit.Test)8 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)7 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)7 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)7