Search in sources :

Example 11 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.

the class DefaultVsAccountService method findByUidSystem.

@Override
public VsAccountDto findByUidSystem(String uidValue, UUID systemId) {
    Assert.notNull(uidValue, "Uid value cannot be null!");
    Assert.notNull(systemId, "Id of CzechIdM system cannot be null!");
    VsAccountFilter filter = new VsAccountFilter();
    filter.setUid(uidValue);
    filter.setSystemId(systemId);
    List<VsAccountDto> accounts = this.find(filter, null).getContent();
    if (accounts.size() > 1) {
        throw new IcException(MessageFormat.format("To many vs accounts for uid [{0}] and system [{1}]!", uidValue, systemId));
    }
    return accounts.isEmpty() ? null : accounts.get(0);
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsAccountFilter(eu.bcvsolutions.idm.vs.dto.filter.VsAccountFilter) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

Example 12 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException 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 13 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException 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 14 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.

the class CzechIdMIcConfigurationService method getAvailableLocalConnectors.

/**
 * Return available local connectors for this IC implementation
 *
 * @return
 */
@SuppressWarnings("unchecked")
@Override
public Set<IcConnectorInfo> getAvailableLocalConnectors() {
    if (connectorInfos == null) {
        connectorInfos = new HashSet<>();
        connectorsConfigurations = new HashMap<>();
        connectorsClass = new HashMap<>();
        List<Class<?>> annotated = new ArrayList<>();
        // Find all class with annotation IcConnectorClass under specific
        // packages
        localConnectorsPackages.forEach(packageWithConnectors -> {
            Reflections reflections = new Reflections(packageWithConnectors);
            annotated.addAll(reflections.getTypesAnnotatedWith(IcConnectorClass.class));
        });
        LOG.info(MessageFormat.format("Found annotated classes with IcConnectorClass [{0}]", annotated));
        for (Class<?> clazz : annotated) {
            IcConnectorClass connectorAnnotation = clazz.getAnnotation(IcConnectorClass.class);
            if (!this.getFramework().equals(connectorAnnotation.framework())) {
                continue;
            }
            if (!IcConnector.class.isAssignableFrom(clazz)) {
                throw new IcException(MessageFormat.format("Cannot create instance of CzechIdM connector [{0}]! Connector class must be child of [{0}]!", IcConnector.class.getSimpleName()));
            }
            IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, (Class<? extends IcConnector>) clazz);
            Class<? extends ConfigurationClass> configurationClass = connectorAnnotation.configurationClass();
            connectorInfos.add(info);
            IcConnectorConfiguration configuration = initDefaultConfiguration(configurationClass);
            // Put default configuration to cache
            connectorsConfigurations.put(info.getConnectorKey().getFullName(), configuration);
            // Put connector class to cache
            connectorsClass.put(info.getConnectorKey().getFullName(), ((Class<? extends IcConnector>) clazz));
        }
        LOG.info(MessageFormat.format("Found all local connector connectorInfos [{0}]", connectorInfos.toString()));
    }
    return connectorInfos;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) ArrayList(java.util.ArrayList) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) Reflections(org.reflections.Reflections)

Example 15 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.

the class CzechIdMIcConfigurationService method getSchema.

@Override
public IcSchema getSchema(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration) {
    Assert.notNull(connectorInstance);
    Assert.notNull(connectorInstance.getConnectorKey());
    Assert.notNull(connectorConfiguration);
    String key = connectorInstance.getConnectorKey().toString();
    LOG.debug("Generate schema - CzechIdM {}", key);
    IcConnector connector = createConnectorInstance(connectorInstance);
    if (!(connector instanceof IcCanGenSchema)) {
        throw new IcException(MessageFormat.format("Connector [{0}] not supports generate schema operation!", key));
    }
    connector.init(connectorConfiguration);
    IcSchema schema = ((IcCanGenSchema) connector).schema();
    LOG.debug("Generated schema - CzechIdM ({}) schema = {}", key, schema);
    return schema;
}
Also used : IcCanGenSchema(eu.bcvsolutions.idm.ic.api.operation.IcCanGenSchema) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcSchema(eu.bcvsolutions.idm.ic.api.IcSchema)

Aggregations

IcException (eu.bcvsolutions.idm.ic.exception.IcException)25 IcConnector (eu.bcvsolutions.idm.ic.api.IcConnector)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)6 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)6 IcConnectorInfo (eu.bcvsolutions.idm.ic.api.IcConnectorInfo)4 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)4 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)4 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)3 IcUidAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)2 IcConnectorInstance (eu.bcvsolutions.idm.ic.api.IcConnectorInstance)2 IcConnectorClass (eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass)2 IcConnectorInstanceImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorInstanceImpl)2 VsVirtualConnector (eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)2 PageRequest (org.springframework.data.domain.PageRequest)2