Search in sources :

Example 1 with EncryptedConfiguration

use of org.candlepin.common.config.EncryptedConfiguration in project candlepin by candlepin.

the class CandlepinContextListener method readConfiguration.

protected Configuration readConfiguration(ServletContext context) throws ConfigurationException {
    // Use StandardCharsets.UTF_8 when we move to Java 7
    Charset utf8 = Charset.forName("UTF-8");
    EncryptedConfiguration systemConfig = new EncryptedConfiguration();
    systemConfig.setEncoding(utf8);
    File configFile = new File(ConfigProperties.DEFAULT_CONFIG_FILE);
    if (configFile.canRead()) {
        log.debug("Loading system configuration");
        // First, read the system configuration
        systemConfig.load(configFile);
        log.debug("System configuration: " + systemConfig);
    }
    systemConfig.use(PASSPHRASE_SECRET_FILE).toDecrypt(ENCRYPTED_PROPERTIES);
    // load the defaults
    MapConfiguration defaults = new MapConfiguration(ConfigProperties.DEFAULT_PROPERTIES);
    // Default to Postgresql if jpa.config.hibernate.dialect is unset
    DatabaseConfigFactory.SupportedDatabase db = determinDatabaseConfiguration(systemConfig.getString("jpa.config.hibernate.dialect", PostgreSQLDialect.class.getName()));
    log.info("Running under {}", db.getLabel());
    Configuration databaseConfig = DatabaseConfigFactory.fetchConfig(db);
    // users should be doing unbidden so it is undocumented.
    return EncryptedConfiguration.merge(systemConfig, databaseConfig, defaults);
}
Also used : MapConfiguration(org.candlepin.common.config.MapConfiguration) Configuration(org.candlepin.common.config.Configuration) EncryptedConfiguration(org.candlepin.common.config.EncryptedConfiguration) MapConfiguration(org.candlepin.common.config.MapConfiguration) Charset(java.nio.charset.Charset) EncryptedConfiguration(org.candlepin.common.config.EncryptedConfiguration) File(java.io.File) DatabaseConfigFactory(org.candlepin.config.DatabaseConfigFactory)

Aggregations

File (java.io.File)1 Charset (java.nio.charset.Charset)1 Configuration (org.candlepin.common.config.Configuration)1 EncryptedConfiguration (org.candlepin.common.config.EncryptedConfiguration)1 MapConfiguration (org.candlepin.common.config.MapConfiguration)1 DatabaseConfigFactory (org.candlepin.config.DatabaseConfigFactory)1