Search in sources :

Example 1 with IcUidAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method internalUpdate.

@Override
public IcUidAttribute internalUpdate(IcUidAttribute uid, IcObjectClass objectClass, List<IcAttribute> attributes) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(attributes, "Attributes cannot be null!");
    Assert.notNull(uid, "UID cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    String uidValue = uid.getUidValue();
    if (uidValue == null) {
        throw new IcException("UID value cannot be null!");
    }
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(uidValue, systemId);
    if (account == null) {
        throw new IcException(MessageFormat.format("Vs account was not found for UID [{0}] and system ID [{1}]!", uidValue, systemId));
    }
    // Update UID - if is different
    IcAttribute uidAttribute = geAttribute(attributes, IcAttributeInfo.NAME);
    if (uidAttribute != null) {
        Object attributeUidValue = uidAttribute.getValue();
        if (!(attributeUidValue instanceof String)) {
            throw new IcException(MessageFormat.format("UID attribute value [{0}] must be String!", attributeUidValue));
        }
        if (!uidValue.equals(attributeUidValue)) {
            // TODO: Connector not supported more entity types!
            LOG.info("Update account - UID is different (old: {} new: {})", uidValue, attributeUidValue);
            account.setUid((String) attributeUidValue);
            account = accountService.save(account);
            // We have to change system entity directly from VS module
            // (request can be started/executed async => standard
            // process update UID in system entity (ACC module) will not
            // works!)
            updateSystemEntity(uidValue, attributeUidValue, true);
        }
    }
    // Update ENABLE - if is different
    IcAttribute enableAttribute = geAttribute(attributes, IcAttributeInfo.ENABLE);
    if (enableAttribute != null && this.virtualConfiguration.isDisableSupported()) {
        Object attributeEnableValue = enableAttribute.getValue();
        if (!(attributeEnableValue instanceof Boolean)) {
            throw new IcException(MessageFormat.format("ENABLE attribute value [{0}] must be Boolean!", attributeEnableValue));
        }
        if (account.isEnable() != (Boolean) attributeEnableValue) {
            account.setEnable((Boolean) attributeEnableValue);
            account = accountService.save(account);
        }
    }
    UUID accountId = account.getId();
    // Update extended attributes
    Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
        updateFormAttributeValue(uidValue, virtualAttirbute, accountId, attributes);
    });
    return new IcUidAttributeImpl(IcAttributeInfo.NAME, account.getUid(), null);
}
Also used : IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) UUID(java.util.UUID)

Example 2 with IcUidAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method searchByPage.

/**
 * Do search for given page and invoke result handler
 *
 * @param handler
 * @param pageable
 */
private void searchByPage(IcResultsHandler handler, Pageable pageable) {
    VsAccountFilter accountFilter = new VsAccountFilter();
    accountFilter.setSystemId(systemId);
    Page<VsAccountDto> resultsPage = accountService.find(accountFilter, pageable);
    List<VsAccountDto> results = resultsPage.getContent();
    results.forEach(account -> {
        boolean canContinue = handler.handle(this.read(new IcUidAttributeImpl(IcAttributeInfo.NAME, account.getUid(), null), new IcObjectClassImpl(IcObjectClassInfo.ACCOUNT)));
        if (!canContinue) {
            // Handler stop next searching
            return;
        }
    });
    if (resultsPage.hasNext()) {
        this.searchByPage(handler, resultsPage.nextPageable());
    }
}
Also used : IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsAccountFilter(eu.bcvsolutions.idm.vs.dto.filter.VsAccountFilter)

Example 3 with IcUidAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method internalCreate.

@Override
public IcUidAttribute internalCreate(IcObjectClass objectClass, List<IcAttribute> attributes) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(attributes, "Attributes cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    IcAttribute uidAttribute = geAttribute(attributes, IcAttributeInfo.NAME);
    if (uidAttribute == null) {
        throw new IcException("UID attribute was not found!");
    }
    Object uidValue = uidAttribute.getValue();
    if (!(uidValue instanceof String)) {
        throw new IcException(MessageFormat.format("UID attribute value [{0}] must be String!", uidValue));
    }
    String uid = (String) uidValue;
    // Find account by UID and System ID - If will be found, then we will do
    // update instead create
    VsAccountDto account = accountService.findByUidSystem(uid, systemId);
    if (account != null) {
        LOG.info("Create account - Virtual system account for UID [{}] already exist. We will execute update!", uidValue);
        return this.internalUpdate(new IcUidAttributeImpl(null, uid, null), objectClass, attributes);
    }
    account = new VsAccountDto();
    // Set ENABLE - if is supported
    IcAttribute enableAttribute = geAttribute(attributes, IcAttributeInfo.ENABLE);
    if (enableAttribute != null && this.virtualConfiguration.isDisableSupported()) {
        Object attributeEnableValue = enableAttribute.getValue();
        if (!(attributeEnableValue instanceof Boolean)) {
            throw new IcException(MessageFormat.format("ENABLE attribute value [{0}] must be Boolean!", attributeEnableValue));
        }
        account.setEnable((Boolean) attributeEnableValue);
    }
    account.setUid(uid);
    account.setSystemId(this.systemId);
    account.setConnectorKey(connectorKey);
    account = accountService.save(account);
    UUID accountId = account.getId();
    // Attributes from definition and configuration
    Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
        updateFormAttributeValue(uidValue, virtualAttirbute, accountId, attributes);
    });
    // We have to change system entity directly (set wish=false!!!) from VS module
    // (request can be started/executed async => standard
    // process update UID in system entity (ACC module) will not
    // works!)
    updateSystemEntity(uid, uid, false);
    return new IcUidAttributeImpl(IcAttributeInfo.NAME, account.getUid(), null);
}
Also used : IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) UUID(java.util.UUID)

Example 4 with IcUidAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestService method internalExecute.

@Override
public IcUidAttribute internalExecute(VsRequestDto request) {
    request.setState(VsRequestState.REALIZED);
    Assert.notNull(request.getConfiguration(), "Request have to contains connector configuration!");
    Assert.notNull(request.getConnectorKey(), "Request have to contains connector key!");
    // Find connector by request
    VsVirtualConnector virtualConnector = getVirtualConnector(request);
    IcUidAttribute result = null;
    // Save the request
    this.save(request);
    switch(request.getOperationType()) {
        case CREATE:
            {
                result = virtualConnector.internalCreate(request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
                break;
            }
        case UPDATE:
            {
                VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
                if (account == null) {
                    throw new VsException(VsResultCode.VS_REQUEST_UPDATING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
                }
                result = virtualConnector.internalUpdate(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
                break;
            }
        case DELETE:
            {
                VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
                if (account == null) {
                    throw new VsException(VsResultCode.VS_REQUEST_DELETING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
                }
                virtualConnector.internalDelete(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass());
                // All unresolved request created before this delete request will be
                // canceled
                VsRequestFilter filter = new VsRequestFilter();
                filter.setCreatedBefore(request.getCreated());
                filter.setUid(request.getUid());
                filter.setSystemId(request.getSystem());
                filter.setState(VsRequestState.IN_PROGRESS);
                // Unresolved request created before this request
                List<VsRequestDto> beforeRequests = this.find(filter, null).getContent();
                beforeRequests.forEach(beforeRequest -> {
                    String reason = MessageFormat.format("Request [{0}] was canceled (by SYSTEM), because 'after' delete request [{1}] was realized!", beforeRequest.getId(), request.getId());
                    this.cancel(beforeRequest, reason);
                    LOG.info(reason);
                });
                break;
            }
        default:
            throw new IcException(MessageFormat.format("Unsupported operation type [{0}]", request.getOperationType()));
    }
    return result;
}
Also used : SysSystem_(eu.bcvsolutions.idm.acc.entity.SysSystem_) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) VsRequestEvent(eu.bcvsolutions.idm.vs.event.VsRequestEvent) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) Predicate(javax.persistence.criteria.Predicate) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Sort(org.springframework.data.domain.Sort) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) DynamicCorsConfiguration(eu.bcvsolutions.idm.core.config.domain.DynamicCorsConfiguration) VsOperationType(eu.bcvsolutions.idm.vs.domain.VsOperationType) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) VsRequest_(eu.bcvsolutions.idm.vs.entity.VsRequest_) ImmutableMap(com.google.common.collect.ImmutableMap) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) List(java.util.List) VsRequest(eu.bcvsolutions.idm.vs.entity.VsRequest) CzechIdMIcConnectorService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConnectorService) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) VsRequestRealizationProcessor(eu.bcvsolutions.idm.vs.event.processor.VsRequestRealizationProcessor) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) VsSystemImplementerService(eu.bcvsolutions.idm.vs.service.api.VsSystemImplementerService) VsRequestRepository(eu.bcvsolutions.idm.vs.repository.VsRequestRepository) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) VsAttributeValueDto(eu.bcvsolutions.idm.vs.dto.VsAttributeValueDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) VsResultCode(eu.bcvsolutions.idm.vs.exception.VsResultCode) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) CollectionUtils(org.apache.commons.collections.CollectionUtils) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) Service(org.springframework.stereotype.Service) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) VsRequestEventType(eu.bcvsolutions.idm.vs.event.VsRequestEvent.VsRequestEventType) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) Direction(org.springframework.data.domain.Sort.Direction) Root(javax.persistence.criteria.Root) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) IcConnectorInstanceImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorInstanceImpl) CzechIdMIcConfigurationService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConfigurationService) VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) Logger(org.slf4j.Logger) VsValueChangeType(eu.bcvsolutions.idm.vs.domain.VsValueChangeType) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsAccountService(eu.bcvsolutions.idm.vs.service.api.VsAccountService) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) VsException(eu.bcvsolutions.idm.vs.exception.VsException) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) VirtualSystemModuleDescriptor(eu.bcvsolutions.idm.vs.VirtualSystemModuleDescriptor) VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) VirtualSystemGroupPermission(eu.bcvsolutions.idm.vs.domain.VirtualSystemGroupPermission) VsRequestService(eu.bcvsolutions.idm.vs.service.api.VsRequestService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) IcException(eu.bcvsolutions.idm.ic.exception.IcException) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) VsException(eu.bcvsolutions.idm.vs.exception.VsException) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) List(java.util.List) ArrayList(java.util.ArrayList) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)

Example 5 with IcUidAttributeImpl

use of eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl 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)

Aggregations

IcUidAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl)11 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)9 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)8 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)7 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)5 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)4 VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)4 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)3 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)3 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)3 IcException (eu.bcvsolutions.idm.ic.exception.IcException)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 UUID (java.util.UUID)3 Test (org.junit.Test)3 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)2 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)2 SysProvisioningOperation (eu.bcvsolutions.idm.acc.entity.SysProvisioningOperation)2 IcConnectorInstance (eu.bcvsolutions.idm.ic.api.IcConnectorInstance)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SysSystem_ (eu.bcvsolutions.idm.acc.entity.SysSystem_)1