Search in sources :

Example 6 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project xwiki-platform by xwiki.

the class XWikiPropertiesConfigurationSource method loadConfiguration.

private Configuration loadConfiguration() {
    // Looking for /etc/xwiki/xwiki.properties first
    File file = new File("/etc/xwiki/" + XWIKI_PROPERTIES_FILE);
    if (file.exists()) {
        try {
            return new Configurations().properties(file);
        } catch (Exception e) {
            // Note: if we cannot read the configuration file for any reason we log a warning but continue since
            // XWiki will use default values for all configurable elements.
            this.logger.warn("Failed to load configuration file [{}]", file, e.getMessage());
        }
    }
    // Register the Commons Properties Configuration, looking for a xwiki.properties file
    // in the XWiki path somewhere.
    URL xwikiPropertiesUrl = null;
    try {
        xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_WARPATH);
        if (xwikiPropertiesUrl != null) {
            FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(new Parameters().properties().setListDelimiterHandler(new DefaultListDelimiterHandler(',')).setURL(xwikiPropertiesUrl));
            return builder.getConfiguration();
        } else {
            // We use a debug logging level here since we consider it's ok that there's no XWIKI_PROPERTIES_FILE
            // available, in which case default values are used.
            this.logger.debug("No configuration file [{}] found. Using default configuration values.", XWIKI_PROPERTIES_WARPATH);
        }
    } catch (Exception e) {
        // Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
        // will use default values for all configurable elements.
        this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. " + "Internal error [{}]", XWIKI_PROPERTIES_WARPATH, e.getMessage());
    }
    // implementation.
    return new BaseConfiguration();
}
Also used : BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration) DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) InitializationException(org.xwiki.component.phase.InitializationException) URL(java.net.URL)

Example 7 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project activemq-artemis by apache.

the class ArtemisTest method checkRole.

private void checkRole(String user, File roleFile, String... roles) throws Exception {
    Configurations configs = new Configurations();
    FileBasedConfigurationBuilder<PropertiesConfiguration> roleBuilder = configs.propertiesBuilder(roleFile);
    PropertiesConfiguration roleConfig = roleBuilder.getConfiguration();
    for (String r : roles) {
        String storedUsers = (String) roleConfig.getProperty(r);
        System.out.println("users in role: " + r + " ; " + storedUsers);
        List<String> userList = StringUtil.splitStringList(storedUsers, ",");
        assertTrue(userList.contains(user));
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 8 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project activemq-artemis by apache.

the class ArtemisTest method checkPassword.

private boolean checkPassword(String user, String password, File userFile) throws Exception {
    Configurations configs = new Configurations();
    FileBasedConfigurationBuilder<PropertiesConfiguration> userBuilder = configs.propertiesBuilder(userFile);
    PropertiesConfiguration userConfig = userBuilder.getConfiguration();
    String storedPassword = (String) userConfig.getProperty(user);
    HashProcessor processor = PasswordMaskingUtil.getHashProcessor(storedPassword);
    return processor.compare(password.toCharArray(), storedPassword);
}
Also used : HashProcessor(org.apache.activemq.artemis.utils.HashProcessor) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 9 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project gocd by gocd.

the class AgentAutoRegistrationPropertiesImpl method scrubRegistrationProperties.

@Override
public void scrubRegistrationProperties() {
    if (!exist()) {
        return;
    }
    try {
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.setIOFactory(new FilteringOutputWriterFactory());
        PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout();
        layout.setLineSeparator("\n");
        layout.load(config, reader());
        try (FileWriter out = new FileWriter(this.configFile)) {
            layout.save(config, out);
        }
        loadProperties();
    } catch (ConfigurationException | IOException e) {
        LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) PropertiesConfigurationLayout(org.apache.commons.configuration2.PropertiesConfigurationLayout)

Example 10 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project vcell by virtualcell.

the class VCellConfiguration method getConfiguration.

private static synchronized Configuration getConfiguration() throws ConfigurationException {
    if (configurationBuilder == null) {
        Parameters params = new Parameters();
        File propertiesFile = new File(ResourceUtil.getVcellHome(), "vcellconfig.properties");
        if (!propertiesFile.exists()) {
            try {
                propertiesFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        FileBasedBuilderParameters thing = params.fileBased().setFile(propertiesFile);
        configurationBuilder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(thing);
        configurationBuilder.setAutoSave(true);
        try {
            propertiesConfiguration = configurationBuilder.getConfiguration();
            propertiesConfiguration.setSynchronizer(new ReadWriteSynchronizer());
        } catch (org.apache.commons.configuration2.ex.ConfigurationException e) {
            e.printStackTrace();
            throw new ConfigurationException("failed to create configuration from file " + propertiesFile + ": " + e.getMessage());
        }
    }
    return propertiesConfiguration;
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) ConfigurationException(org.vcell.util.ConfigurationException) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) ReadWriteSynchronizer(org.apache.commons.configuration2.sync.ReadWriteSynchronizer) IOException(java.io.IOException) File(java.io.File)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)28 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)10 File (java.io.File)7 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)5 Configuration (org.apache.commons.configuration2.Configuration)4 Configurations (org.apache.commons.configuration2.builder.fluent.Configurations)4 FileReader (java.io.FileReader)3 FileBasedConfigurationBuilder (org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 StringWriter (java.io.StringWriter)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 BaseConfiguration (org.apache.commons.configuration2.BaseConfiguration)2 PropertiesBuilderParameters (org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters)2 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)2 Preconditions (com.google.common.base.Preconditions)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1