Search in sources :

Example 1 with ConfigFilter

use of org.apache.deltaspike.core.spi.config.ConfigFilter in project deltaspike by apache.

the class ConfigResolver method filterConfigValueForLog.

/**
     * Filter the configured value for logging.
     * This can e.g. be used for displaying ***** instead of a real password.
     * @return the filtered value
     */
public static String filterConfigValueForLog(String key, String value) {
    List<ConfigFilter> currentConfigFilters = getInternalConfigFilters();
    String logValue = value;
    for (ConfigFilter filter : currentConfigFilters) {
        logValue = filter.filterValueForLog(key, logValue);
    }
    return logValue;
}
Also used : ConfigFilter(org.apache.deltaspike.core.spi.config.ConfigFilter)

Example 2 with ConfigFilter

use of org.apache.deltaspike.core.spi.config.ConfigFilter in project deltaspike by apache.

the class ConfigResolver method filterConfigValue.

/**
     * Filter the configured value.
     * This can e.g. be used for decryption.
     * @return the filtered value
     */
public static String filterConfigValue(String key, String value) {
    List<ConfigFilter> currentConfigFilters = getInternalConfigFilters();
    String filteredValue = value;
    for (ConfigFilter filter : currentConfigFilters) {
        filteredValue = filter.filterValue(key, filteredValue);
    }
    return filteredValue;
}
Also used : ConfigFilter(org.apache.deltaspike.core.spi.config.ConfigFilter)

Example 3 with ConfigFilter

use of org.apache.deltaspike.core.spi.config.ConfigFilter in project deltaspike by apache.

the class ConfigImpl method init.

/**
 * Performs all the initialisation of the default
 * ConfigSources, ConfigFilters, etc
 */
void init() {
    List<ConfigSource> appConfigSources = ServiceUtils.loadServiceImplementations(ConfigSource.class, false, classLoader);
    List<ConfigSourceProvider> configSourceProviderServiceLoader = ServiceUtils.loadServiceImplementations(ConfigSourceProvider.class, false, classLoader);
    for (ConfigSourceProvider configSourceProvider : configSourceProviderServiceLoader) {
        appConfigSources.addAll(configSourceProvider.getConfigSources());
    }
    addConfigSources(appConfigSources);
    if (LOG.isLoggable(Level.FINE)) {
        for (ConfigSource cs : appConfigSources) {
            LOG.log(Level.FINE, "Adding ordinal {0} ConfigSource {1}", new Object[] { cs.getOrdinal(), cs.getConfigName() });
        }
    }
    List<ConfigFilter> configFilters = ServiceUtils.loadServiceImplementations(ConfigFilter.class, false, classLoader);
    this.configFilters = new CopyOnWriteArrayList<>(configFilters);
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) ConfigSourceProvider(org.apache.deltaspike.core.spi.config.ConfigSourceProvider) ConfigFilter(org.apache.deltaspike.core.spi.config.ConfigFilter)

Example 4 with ConfigFilter

use of org.apache.deltaspike.core.spi.config.ConfigFilter in project deltaspike by apache.

the class ConfigResolverTest method testConfigFilter.

@Test
public void testConfigFilter() {
    ConfigFilter configFilter = new TestConfigFilter();
    Assert.assertEquals("shouldGetDecrypted: value", configFilter.filterValue("somekey.encrypted", "value"));
    Assert.assertEquals("**********", configFilter.filterValueForLog("somekey.password", "value"));
    ConfigResolver.addConfigFilter(configFilter);
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyValue("testkey4.encrypted"));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getProjectStageAwarePropertyValue("testkey4.encrypted"));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getProjectStageAwarePropertyValue("testkey4.encrypted", null));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyAwarePropertyValue("testkey4.encrypted", "dbvendor"));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyAwarePropertyValue("testkey4.encrypted", "dbvendor", null));
    List<String> allPropertyValues = ConfigResolver.getAllPropertyValues("testkey4.encrypted");
    Assert.assertNotNull(allPropertyValues);
    Assert.assertEquals(1, allPropertyValues.size());
    Assert.assertEquals("shouldGetDecrypted: value", allPropertyValues.get(0));
}
Also used : ConfigFilter(org.apache.deltaspike.core.spi.config.ConfigFilter) Test(org.junit.Test)

Example 5 with ConfigFilter

use of org.apache.deltaspike.core.spi.config.ConfigFilter in project deltaspike by apache.

the class ConfigResolver method resolveConfigSources.

private static List<ConfigSource> resolveConfigSources() {
    List<ConfigSource> appConfigSources = ServiceUtils.loadServiceImplementations(ConfigSource.class);
    List<ConfigSourceProvider> configSourceProviderServiceLoader = ServiceUtils.loadServiceImplementations(ConfigSourceProvider.class);
    for (ConfigSourceProvider configSourceProvider : configSourceProviderServiceLoader) {
        appConfigSources.addAll(configSourceProvider.getConfigSources());
    }
    List<? extends ConfigFilter> configFilters = ServiceUtils.loadServiceImplementations(ConfigFilter.class);
    for (ConfigFilter configFilter : configFilters) {
        addConfigFilter(configFilter);
    }
    return appConfigSources;
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) ConfigSourceProvider(org.apache.deltaspike.core.spi.config.ConfigSourceProvider) ConfigFilter(org.apache.deltaspike.core.spi.config.ConfigFilter)

Aggregations

ConfigFilter (org.apache.deltaspike.core.spi.config.ConfigFilter)6 ConfigSource (org.apache.deltaspike.core.spi.config.ConfigSource)2 ConfigSourceProvider (org.apache.deltaspike.core.spi.config.ConfigSourceProvider)2 Test (org.junit.Test)2