use of io.gravitee.common.util.RelaxedPropertySource in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentBeanFactoryPostProcessor method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
StandardEnvironment environment = (StandardEnvironment) beanFactory.getBean(Environment.class);
if (environment != null) {
Map<String, Object> systemEnvironment = environment.getSystemEnvironment();
Map<String, Object> prefixlessSystemEnvironment = new HashMap<>(systemEnvironment.size());
systemEnvironment.keySet().forEach(key -> {
String prefixKey = key;
for (String propertyPrefix : PROPERTY_PREFIXES) {
if (key.startsWith(propertyPrefix)) {
prefixKey = key.substring(propertyPrefix.length());
break;
}
}
prefixlessSystemEnvironment.put(prefixKey, systemEnvironment.get(key));
});
environment.getPropertySources().replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new RelaxedPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, prefixlessSystemEnvironment));
}
}
use of io.gravitee.common.util.RelaxedPropertySource in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderManagerImpl method create.
private <T> T create(Plugin plugin, Class<T> identityClass, Map<String, Object> properties) {
if (identityClass == null) {
return null;
}
try {
T identityObj = createInstance(identityClass);
final Import annImport = identityClass.getAnnotation(Import.class);
Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet();
ApplicationContext idpApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) {
@Override
public Set<Class<?>> configurations() {
return configurations;
}
@Override
public ConfigurableEnvironment environment() {
return new StandardEnvironment() {
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
propertySources.addFirst(new RelaxedPropertySource(plugin.id(), properties));
super.customizePropertySources(propertySources);
}
};
}
});
idpApplicationContext.getAutowireCapableBeanFactory().autowireBean(identityObj);
if (identityObj instanceof InitializingBean) {
((InitializingBean) identityObj).afterPropertiesSet();
}
return identityObj;
} catch (Exception ex) {
LOGGER.error("An unexpected error occurs while loading identity provider", ex);
return null;
}
}
use of io.gravitee.common.util.RelaxedPropertySource in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentBeanFactoryPostProcessor method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
StandardEnvironment environment = (StandardEnvironment) beanFactory.getBean(Environment.class);
Map<String, Object> systemEnvironment = environment.getSystemEnvironment();
Map<String, Object> prefixlessSystemEnvironment = new HashMap<>(systemEnvironment.size());
systemEnvironment.keySet().forEach(key -> {
String prefixKey = key;
for (String propertyPrefix : PROPERTY_PREFIXES) {
if (key.startsWith(propertyPrefix)) {
prefixKey = key.substring(propertyPrefix.length());
break;
}
}
prefixlessSystemEnvironment.put(prefixKey, systemEnvironment.get(key));
});
environment.getPropertySources().replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new RelaxedPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, prefixlessSystemEnvironment));
}
Aggregations