Search in sources :

Example 1 with VsVirtualConnector

use of eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestService method getVirtualConnector.

/**
 * Get virtual connector by vs request
 *
 * @param request
 * @return
 */
private VsVirtualConnector getVirtualConnector(VsRequestDto request) {
    IcConnectorInfo connectorInfo = // 
    czechIdMConfigurationService.getAvailableLocalConnectors().stream().filter(// 
    info -> request.getConnectorKey().equals(info.getConnectorKey().getFullName())).findFirst().orElse(null);
    if (connectorInfo == null) {
        throw new IcException(MessageFormat.format("We cannot found connector info by connector key [{0}] from virtual system request!", request.getConnectorKey()));
    }
    IcConnectorInstance connectorKeyInstance = new IcConnectorInstanceImpl(null, connectorInfo.getConnectorKey(), false);
    IcConnector connectorInstance = czechIdMConnectorService.getConnectorInstance(connectorKeyInstance, request.getConfiguration());
    if (!(connectorInstance instanceof VsVirtualConnector)) {
        throw new IcException("Found connector instance is not virtual system connector!");
    }
    VsVirtualConnector virtualConnector = (VsVirtualConnector) connectorInstance;
    return virtualConnector;
}
Also used : IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) IcConnectorInstanceImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorInstanceImpl) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)

Example 2 with VsVirtualConnector

use of eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector 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_) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) 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) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) Predicate(javax.persistence.criteria.Predicate) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) VsSystemService(eu.bcvsolutions.idm.vs.service.api.VsSystemService) Sort(org.springframework.data.domain.Sort) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) Path(javax.persistence.criteria.Path) 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) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) List(java.util.List) VsRequest(eu.bcvsolutions.idm.vs.entity.VsRequest) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) CzechIdMIcConnectorService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConnectorService) 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) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) MessageFormat(java.text.MessageFormat) VsResultCode(eu.bcvsolutions.idm.vs.exception.VsResultCode) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) CollectionUtils(org.apache.commons.collections.CollectionUtils) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) VsRequestEventType(eu.bcvsolutions.idm.vs.event.VsRequestEvent.VsRequestEventType) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) VsSystemImplementer(eu.bcvsolutions.idm.vs.entity.VsSystemImplementer) Direction(org.springframework.data.domain.Sort.Direction) Root(javax.persistence.criteria.Root) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) CzechIdMIcConfigurationService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConfigurationService) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) Logger(org.slf4j.Logger) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsAccountService(eu.bcvsolutions.idm.vs.service.api.VsAccountService) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) VsException(eu.bcvsolutions.idm.vs.exception.VsException) VsSystemImplementer_(eu.bcvsolutions.idm.vs.entity.VsSystemImplementer_) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) VirtualSystemModuleDescriptor(eu.bcvsolutions.idm.vs.VirtualSystemModuleDescriptor) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) Subquery(javax.persistence.criteria.Subquery) 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) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)

Example 3 with VsVirtualConnector

use of eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector in project CzechIdMng by bcvsolutions.

the class DefaultVsSystemService method getVirtualConnector.

@Transactional
@Override
public VsVirtualConnector getVirtualConnector(UUID systemId, String connectorKey) {
    Assert.notNull(systemId, "System identifier is required.");
    Assert.notNull(connectorKey, "Connector key is required.");
    IcConnectorInfo connectorInfo = this.getConnectorInfo(connectorKey);
    if (connectorInfo == null) {
        throw new IcException(MessageFormat.format("We cannot found connector info by connector key [{0}] from virtual system request!", connectorKey));
    }
    IcConnector connectorInstance = this.getConnectorInstance(systemId, connectorInfo);
    if (!(connectorInstance instanceof VsVirtualConnector)) {
        throw new IcException("Found connector instance is not virtual system connector!");
    }
    VsVirtualConnector virtualConnector = (VsVirtualConnector) connectorInstance;
    return virtualConnector;
}
Also used : IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with VsVirtualConnector

use of eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector in project CzechIdMng by bcvsolutions.

the class DefaultVsSystemService method create.

@Transactional
@Override
public SysSystemDto create(VsSystemDto vsSystem) {
    Assert.notNull(vsSystem, "Vs system dto cannot be null (for create new virtual system)");
    Assert.notNull(vsSystem.getName(), "Vs system name cannot be null (for create new virtual system)");
    LOG.info("Create new virtual system with name [{}].", vsSystem.getName());
    SysSystemDto system = new SysSystemDto();
    // Find connector for VS
    Class<? extends VsVirtualConnector> defaultVirtualConnector = BasicVirtualConnector.class;
    IcConnectorClass connectorAnnotation = defaultVirtualConnector.getAnnotation(IcConnectorClass.class);
    IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, (Class<? extends IcConnector>) defaultVirtualConnector);
    // Set connector key for VS
    system.setConnectorKey(new SysConnectorKeyDto(info.getConnectorKey()));
    system.setName(vsSystem.getName());
    // Create system
    system = this.systemService.save(system, IdmBasePermission.CREATE);
    // Find and update attribute for implementers
    IdmFormDefinitionDto connectorFormDef = this.systemService.getConnectorFormDefinition(system);
    IdmFormAttributeDto implementersFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTERS_PROPERTY);
    formService.saveValues(system, implementersFormAttr, new ArrayList<>(vsSystem.getImplementers()));
    // Find and update attribute for implementers by roles
    IdmFormAttributeDto implementerRolesFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTER_ROLES_PROPERTY);
    formService.saveValues(system, implementerRolesFormAttr, new ArrayList<>(vsSystem.getImplementerRoles()));
    // Find and update attribute for properties
    IdmFormAttributeDto attributesFormAttr = connectorFormDef.getMappedAttributeByCode(ATTRIBUTES_PROPERTY);
    if (!vsSystem.getAttributes().isEmpty()) {
        formService.saveValues(system, attributesFormAttr, new ArrayList<>(vsSystem.getAttributes()));
    } else {
        List<Serializable> defaultAttributes = Lists.newArrayList((Serializable[]) BasicVirtualConfiguration.DEFAULT_ATTRIBUTES);
        defaultAttributes.add(RIGHTS_ATTRIBUTE);
        formService.saveValues(system, attributesFormAttr, defaultAttributes);
    }
    // Update virtual system configuration (implementers and definition)
    VsVirtualConnector virtualConnector = this.getVirtualConnector(system.getId(), system.getConnectorKey().getFullName());
    Assert.notNull(virtualConnector, "Connector is required.");
    this.updateSystemConfiguration(virtualConnector.getConfiguration(), virtualConnector.getClass());
    system = systemService.get(system.getId());
    // Search attribute definition for rights and set him to multivalue
    String virtualSystemKey = createVsFormDefinitionKey(system);
    String type = VsAccount.class.getName();
    IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
    IdmFormAttributeDto rightsFormAttr = formAttributeService.findAttribute(type, definition.getCode(), RIGHTS_ATTRIBUTE);
    if (rightsFormAttr != null) {
        rightsFormAttr.setMultiple(true);
        formService.saveAttribute(rightsFormAttr);
    }
    // Update virtual system configuration (rights attribute ... multivalued)
    virtualConnector = this.getVirtualConnector(system.getId(), system.getConnectorKey().getFullName());
    this.updateSystemConfiguration(virtualConnector.getConfiguration(), virtualConnector.getClass());
    this.systemService.checkSystem(system);
    // Generate schema
    List<SysSchemaObjectClassDto> schemas = this.systemService.generateSchema(system);
    SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> IcObjectClassInfo.ACCOUNT.equals(schema.getObjectClassName())).findFirst().orElse(null);
    Assert.notNull(schemaAccount, "We cannot found schema for ACCOUNT!");
    // Create mapping by default attributes
    SysSystemMappingDto defaultMapping = this.createDefaultMapping(system, schemaAccount, vsSystem);
    // Create mapping for Connection
    SysSystemMappingDto foundMapping = createMapping(system, schemaAccount.getId());
    Assert.notNull(foundMapping, "Mapping not found!");
    SysSystemAttributeMappingDto attributeMapping = createAttributeMapping(foundMapping.getId(), schemaAccount.getId());
    Assert.notNull(attributeMapping, "Attribute Mapping not found!");
    // Create default role
    IdmRoleDto role = createRoleAndConnectToSystem(vsSystem, system, defaultMapping.getId());
    SysSyncIdentityConfigDto synchronization = createReconciliationConfig(attributeMapping.getId(), foundMapping.getId(), system.getId(), role == null ? null : role.getId());
    Assert.notNull(synchronization, "Synchronization not found!");
    return this.systemService.get(system.getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) Serializable(java.io.Serializable) BasicVirtualConnector(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConnector) SysConnectorKeyDto(eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with VsVirtualConnector

use of eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector in project CzechIdMng by bcvsolutions.

the class SystemSaveProcessor method process.

@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
    SysSystemDto system = event.getContent();
    Assert.notNull(system, "System is required.");
    UUID systemId = system.getId();
    Assert.notNull(systemId, "System identifier is required.");
    SysConnectorKeyDto connectorKey = system.getConnectorKey();
    Assert.notNull(connectorKey, "Connector key is required.");
    VsVirtualConnector virtualConnector = vsSystemService.getVirtualConnector(systemId, connectorKey.getFullName());
    Assert.notNull(virtualConnector, "Connector is required.");
    // Update configuration (implementers, definition)
    vsSystemService.updateSystemConfiguration(virtualConnector.getConfiguration(), virtualConnector.getClass());
    return new DefaultEventResult<>(event, this);
}
Also used : SysConnectorKeyDto(eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

VsVirtualConnector (eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)6 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 IcConnectorInfo (eu.bcvsolutions.idm.ic.api.IcConnectorInfo)4 IcConnector (eu.bcvsolutions.idm.ic.api.IcConnector)3 IcException (eu.bcvsolutions.idm.ic.exception.IcException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SysConnectorKeyDto (eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto)2 UUID (java.util.UUID)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 SysAttributeDifferenceDto (eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto)1 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)1 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 SysSystem_ (eu.bcvsolutions.idm.acc.entity.SysSystem_)1 AccAccountService (eu.bcvsolutions.idm.acc.service.api.AccAccountService)1 SynchronizationEntityExecutor (eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor)1 SysProvisioningArchiveService (eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService)1