Search in sources :

Example 1 with RelaxedPropertySource

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));
    }
}
Also used : HashMap(java.util.HashMap) Environment(org.springframework.core.env.Environment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) RelaxedPropertySource(io.gravitee.common.util.RelaxedPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 2 with RelaxedPropertySource

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;
    }
}
Also used : Import(org.springframework.context.annotation.Import) AnnotationBasedPluginContextConfigurer(io.gravitee.plugin.core.internal.AnnotationBasedPluginContextConfigurer) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) InitializingBean(org.springframework.beans.factory.InitializingBean) RelaxedPropertySource(io.gravitee.common.util.RelaxedPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 3 with RelaxedPropertySource

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));
}
Also used : HashMap(java.util.HashMap) Environment(org.springframework.core.env.Environment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) RelaxedPropertySource(io.gravitee.common.util.RelaxedPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Aggregations

RelaxedPropertySource (io.gravitee.common.util.RelaxedPropertySource)3 StandardEnvironment (org.springframework.core.env.StandardEnvironment)3 HashMap (java.util.HashMap)2 Environment (org.springframework.core.env.Environment)2 AnnotationBasedPluginContextConfigurer (io.gravitee.plugin.core.internal.AnnotationBasedPluginContextConfigurer)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Import (org.springframework.context.annotation.Import)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 MutablePropertySources (org.springframework.core.env.MutablePropertySources)1