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);
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations