Search in sources :

Example 1 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 2 with IcException

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

the class CzechIdMIcConnectorService method updateObject.

@Override
public IcUidAttribute updateObject(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, IcUidAttribute uid, List<IcAttribute> replaceAttributes) {
    Assert.notNull(connectorInstance, "Connector instance is required.");
    Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
    Assert.notNull(connectorConfiguration, "Configuration is required.");
    Assert.notNull(replaceAttributes, "Replace attributes are required.");
    Assert.notNull(uid, "Uid is required.");
    String key = connectorInstance.getConnectorKey().toString();
    LOG.debug("Update object - CzechIdM (Uid= {} {} {})", uid, key, replaceAttributes.toString());
    if (objectClass == null) {
        objectClass = new IcObjectClassImpl(IcObjectClassInfo.ACCOUNT);
    }
    IcConnector connector = this.getConnectorInstance(connectorInstance, connectorConfiguration);
    if (!(connector instanceof IcCanUpdate)) {
        throw new IcException(MessageFormat.format("Connector [{0}] not supports update operation!", key));
    }
    IcUidAttribute updatedUid = ((IcCanUpdate) connector).update(uid, objectClass, replaceAttributes);
    LOG.debug("Updated object - CzechIdM ({} {}) Uid= {})", connectorInstance.getConnectorKey().toString(), replaceAttributes.toString(), updatedUid);
    return updatedUid;
}
Also used : IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcCanUpdate(eu.bcvsolutions.idm.ic.api.operation.IcCanUpdate) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) IcException(eu.bcvsolutions.idm.ic.exception.IcException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute)

Example 3 with IcException

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

the class CzechIdMIcConnectorService method getConnectorInstance.

@Override
public IcConnector getConnectorInstance(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration) {
    Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
    Assert.notNull(connectorConfiguration, "Configuration is required.");
    // String key = connectorInstance.getConnectorKey().getFullName();
    // Cache is not thread safety
    // if(this.connectorInstances.containsKey(key)){
    // IcConnector connector = connectorInstances.get(key);
    // connector.init(connectorConfiguration);
    // return connector;
    // }
    Class<? extends IcConnector> connectorClass = this.configurationService.getConnectorClass(connectorInstance);
    try {
        IcConnector connector = connectorClass.getDeclaredConstructor().newInstance();
        // Manually autowire on this connector instance
        this.applicationContext.getAutowireCapableBeanFactory().autowireBean(connector);
        connector.init(connectorConfiguration);
        // this.connectorInstances.put(key, connector);
        return connector;
    } catch (ReflectiveOperationException e) {
        throw new IcException(e);
    }
}
Also used : IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

Example 4 with IcException

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

the class CzechIdMIcConnectorService method synchronization.

@Override
public IcSyncToken synchronization(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, IcSyncToken token, IcSyncResultsHandler handler) {
    Assert.notNull(connectorInstance, "Connector instance is required.");
    Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
    Assert.notNull(connectorConfiguration, "Configuration is required.");
    Assert.notNull(objectClass, "Object class is required.");
    Assert.notNull(handler, "Handler is required.");
    String key = connectorInstance.getConnectorKey().toString();
    LOG.debug("Start synchronization for connector {} and objectClass {} - CzechIdM", key, objectClass.getDisplayName());
    throw new IcException(MessageFormat.format("Connector [{0}] not supports sync operation!", key));
}
Also used : IcException(eu.bcvsolutions.idm.ic.exception.IcException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Example 5 with IcException

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

the class CzechIdMIcConvertUtil method convertIcConnectorConfiguration.

public static ConfigurationClass convertIcConnectorConfiguration(IcConnectorConfiguration configuration, Class<? extends ConfigurationClass> configurationClass) {
    if (configuration == null || configuration.getConfigurationProperties() == null || configuration.getConfigurationProperties().getProperties() == null) {
        return null;
    }
    List<IcConfigurationProperty> properties = configuration.getConfigurationProperties().getProperties();
    try {
        ConfigurationClass configurationClassInstance = configurationClass.getDeclaredConstructor().newInstance();
        PropertyDescriptor[] descriptors;
        descriptors = Introspector.getBeanInfo(configurationClass).getPropertyDescriptors();
        Lists.newArrayList(descriptors).stream().forEach(descriptor -> {
            String propertyName = descriptor.getName();
            Method writeMethod = descriptor.getWriteMethod();
            IcConfigurationProperty propertyToConvert = properties.stream().filter(property -> propertyName.equals(property.getName())).findFirst().orElse(null);
            if (propertyToConvert == null) {
                return;
            }
            try {
                writeMethod.invoke(configurationClassInstance, propertyToConvert.getValue());
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw new IcException(e);
            }
        });
        return configurationClassInstance;
    } catch (IntrospectionException | ReflectiveOperationException e) {
        throw new IcException(e);
    }
}
Also used : ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) IcException(eu.bcvsolutions.idm.ic.exception.IcException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) IcConfigurationProperty(eu.bcvsolutions.idm.ic.api.IcConfigurationProperty)

Aggregations

IcException (eu.bcvsolutions.idm.ic.exception.IcException)27 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)5 UUID (java.util.UUID)5 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)4 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)3 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)3 IcConnectorClass (eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass)3 IcUidAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl)3 VsVirtualConnector (eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)2 IcConnectorConfigurationCzechIdMImpl (eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl)2 BasicVirtualConfiguration (eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration)2 ArrayList (java.util.ArrayList)2