Search in sources :

Example 1 with IcConfigurationProperty

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

the class DefaultSysSystemServiceTest method testFillConnectorConfiguration.

@Test
public void testFillConnectorConfiguration() {
    // create owner
    @SuppressWarnings("deprecation") SysSystemDto system = systemService.createTestSystem();
    IcConnectorConfiguration connectorConfiguration = systemService.getConnectorConfiguration(system);
    assertEquals(15, connectorConfiguration.getConfigurationProperties().getProperties().size());
    // 
    // check all supported data types
    // TODO: add all supported types
    Integer checked = 0;
    for (IcConfigurationProperty property : connectorConfiguration.getConfigurationProperties().getProperties()) {
        switch(property.getName()) {
            case "host":
                {
                    assertEquals("localhost", property.getValue());
                    checked++;
                    break;
                }
            case "password":
                {
                    assertEquals(new org.identityconnectors.common.security.GuardedString("idmadmin".toCharArray()), property.getValue());
                    checked++;
                    break;
                }
            case "rethrowAllSQLExceptions":
                {
                    assertEquals(true, property.getValue());
                    checked++;
                    break;
                }
        }
    }
    ;
    assertEquals(Integer.valueOf(3), checked);
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcConfigurationProperty(eu.bcvsolutions.idm.ic.api.IcConfigurationProperty) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with IcConfigurationProperty

use of eu.bcvsolutions.idm.ic.api.IcConfigurationProperty 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.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 | InstantiationException | IllegalAccessException 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)

Example 3 with IcConfigurationProperty

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

the class CzechIdMIcConfigurationService method initDefaultConfiguration.

/**
 * Create instance of default connector configuration
 *
 * @param configurationClass
 * @return
 */
private IcConnectorConfiguration initDefaultConfiguration(Class<? extends ConfigurationClass> configurationClass) {
    try {
        ConfigurationClass configurationClassInstance = configurationClass.newInstance();
        List<IcConfigurationProperty> properties = new ArrayList<>();
        PropertyDescriptor[] descriptors = Introspector.getBeanInfo(configurationClass).getPropertyDescriptors();
        Lists.newArrayList(descriptors).stream().forEach(descriptor -> {
            Method readMethod = descriptor.getReadMethod();
            String propertyName = descriptor.getName();
            ConfigurationClassProperty property = readMethod.getAnnotation(ConfigurationClassProperty.class);
            if (property != null) {
                IcConfigurationPropertyImpl icProperty = (IcConfigurationPropertyImpl) CzechIdMIcConvertUtil.convertConfigurationProperty(property);
                icProperty.setName(propertyName);
                icProperty.setType(readMethod.getGenericReturnType().getTypeName());
                try {
                    icProperty.setValue(readMethod.invoke(configurationClassInstance));
                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    throw new CoreException("Cannot read value of connector configuration property!", e);
                }
                properties.add(icProperty);
            }
        });
        // Sort by order
        properties.sort(Comparator.comparing(IcConfigurationProperty::getOrder));
        IcConfigurationPropertiesImpl icProperties = new IcConfigurationPropertiesImpl();
        icProperties.setProperties(properties);
        IcConnectorConfigurationImpl configuration = new IcConnectorConfigurationImpl();
        configuration.setConnectorPoolingSupported(false);
        configuration.setConfigurationProperties(icProperties);
        return configuration;
    } catch (IntrospectionException | InstantiationException | IllegalAccessException e) {
        throw new CoreException("Cannot read connector configuration property!", e);
    }
}
Also used : ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) IcConnectorConfigurationImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorConfigurationImpl) PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method) IcConfigurationPropertiesImpl(eu.bcvsolutions.idm.ic.impl.IcConfigurationPropertiesImpl) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationClassProperty(eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IcConfigurationProperty(eu.bcvsolutions.idm.ic.api.IcConfigurationProperty) IcConfigurationPropertyImpl(eu.bcvsolutions.idm.ic.impl.IcConfigurationPropertyImpl)

Example 4 with IcConfigurationProperty

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

the class DefaultSysSystemService method getConnectorConfiguration.

@Override
@Transactional
public IcConnectorConfiguration getConnectorConfiguration(SysSystemDto system) {
    Assert.notNull(system);
    if (system.getConnectorKey() == null) {
        return null;
    }
    IcConnectorConfiguration connectorConfig = null;
    // load connector properties, different between local and remote
    IcConnectorInstance connectorInstance = system.getConnectorInstance();
    if (system.isRemote() && connectorInstance.getConnectorServer() != null) {
        connectorInstance.getConnectorServer().setPassword(confidentialStorage.getGuardedString(system.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
    }
    connectorConfig = icConfigurationFacade.getConnectorConfiguration(connectorInstance);
    // load filled form values
    IdmFormDefinitionDto formDefinition = getConnectorFormDefinition(system.getConnectorInstance());
    IdmFormInstanceDto formValues = getFormService().getFormInstance(system, formDefinition);
    Map<String, List<IdmFormValueDto>> attributeValues = formValues.toValueMap();
    // fill connector configuration from form values
    IcConnectorConfigurationImpl icConf = null;
    if (SysSystemService.CONNECTOR_FRAMEWORK_CZECHIDM.equals(connectorInstance.getConnectorKey().getFramework())) {
        // For CzechIdM connector framework is needs system ID (exactly for virtual systems).
        icConf = new IcConnectorConfigurationCzechIdMImpl();
        ((IcConnectorConfigurationCzechIdMImpl) icConf).setSystemId(system.getId());
    } else {
        icConf = new IcConnectorConfigurationImpl();
    }
    IcConfigurationProperties properties = new IcConfigurationPropertiesImpl();
    icConf.setConfigurationProperties(properties);
    // 
    for (short seq = 0; seq < connectorConfig.getConfigurationProperties().getProperties().size(); seq++) {
        IcConfigurationProperty propertyConfig = connectorConfig.getConfigurationProperties().getProperties().get(seq);
        IdmFormAttributeDto formAttribute = formDefinition.getMappedAttributeByCode(propertyConfig.getName());
        List<IdmFormValueDto> eavAttributeValues = attributeValues.get(formAttribute.getCode());
        // create property instance from configuration
        IcConfigurationProperty property = formPropertyManager.toConnectorProperty(propertyConfig, eavAttributeValues);
        if (property.getValue() != null) {
            // only filled values to configuration
            properties.getProperties().add(property);
        }
    }
    return icConf;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IcConnectorConfigurationImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorConfigurationImpl) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IcConfigurationPropertiesImpl(eu.bcvsolutions.idm.ic.impl.IcConfigurationPropertiesImpl) IcConfigurationProperties(eu.bcvsolutions.idm.ic.api.IcConfigurationProperties) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IcConfigurationProperty(eu.bcvsolutions.idm.ic.api.IcConfigurationProperty) IcConnectorConfigurationCzechIdMImpl(eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) List(java.util.List) ArrayList(java.util.ArrayList) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with IcConfigurationProperty

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

the class DefaultSysSystemService method createConnectorFormDefinition.

/**
 * Create form definition to given connectorInstance by connector properties
 *
 * @param connectorKey
 * @return
 */
private synchronized IdmFormDefinitionDto createConnectorFormDefinition(IcConnectorInstance connectorInstance) {
    IcConnectorConfiguration conf = icConfigurationFacade.getConnectorConfiguration(connectorInstance);
    if (conf == null) {
        throw new IllegalStateException(MessageFormat.format("Connector with key [{0}] was not found on classpath.", connectorInstance.getConnectorKey().getFullName()));
    }
    // 
    List<IdmFormAttributeDto> formAttributes = new ArrayList<>();
    for (short seq = 0; seq < conf.getConfigurationProperties().getProperties().size(); seq++) {
        IcConfigurationProperty property = conf.getConfigurationProperties().getProperties().get(seq);
        IdmFormAttributeDto attribute = formPropertyManager.toFormAttribute(property);
        attribute.setSeq(seq);
        formAttributes.add(attribute);
    }
    return getFormService().createDefinition(SysSystem.class.getName(), connectorInstance.getConnectorKey().getFullName(), formAttributes);
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IcConfigurationProperty(eu.bcvsolutions.idm.ic.api.IcConfigurationProperty) ArrayList(java.util.ArrayList)

Aggregations

IcConfigurationProperty (eu.bcvsolutions.idm.ic.api.IcConfigurationProperty)6 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)3 ArrayList (java.util.ArrayList)3 SysSystem (eu.bcvsolutions.idm.acc.entity.SysSystem)2 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)2 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)2 IcConfigurationProperties (eu.bcvsolutions.idm.ic.api.IcConfigurationProperties)2 IcConfigurationPropertiesImpl (eu.bcvsolutions.idm.ic.impl.IcConfigurationPropertiesImpl)2 IcConnectorConfigurationImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorConfigurationImpl)2 IntrospectionException (java.beans.IntrospectionException)2 PropertyDescriptor (java.beans.PropertyDescriptor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 ConfigurationClassProperty (eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)1 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)1 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1