Example usage for org.apache.commons.configuration ConfigurationConverter getProperties

List of usage examples for org.apache.commons.configuration ConfigurationConverter getProperties

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationConverter getProperties.

Prototype

public static Properties getProperties(Configuration config) 

Source Link

Document

Convert a Configuration class into a Properties class.

Usage

From source file:com.ariht.maven.plugins.config.generator.ConfigGeneratorImpl.java

/**
 * Filter io contain the properties we wish to substitute in templates.
 *
 * Uses Apache Commons Configuration to load filters.
 *///from  w  ww.ja  v  a 2 s. co m
private Properties readFilterIntoProperties(final FileInfo filter) throws ConfigurationException, IOException {
    final CompositeConfiguration composite = new CompositeConfiguration();
    final List<File> files = filter.getFiles();
    for (final File file : files) {
        final PropertiesConfiguration config = new PropertiesConfiguration(file);
        config.setEncoding(configGeneratorParameters.getEncoding());
        composite.addConfiguration(config);
    }
    if (StringUtils.isNotBlank(configGeneratorParameters.getFilterSourcePropertyName())) {
        composite.setProperty(configGeneratorParameters.getFilterSourcePropertyName(), filter.getAllSources());
    }
    return ConfigurationConverter.getProperties(composite);
}

From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java

@Override
public void initializeSecuritySettings() {
    try {/*from   w w w.  j a v a 2 s.c  om*/
        /*
         * Load the encryption settings so that they can be referenced client side.
         */
        encryptionConfig = new EncryptionSettings(ConfigurationConverter.getProperties(mirthConfig));

        File keyStoreFile = new File(mirthConfig.getString("keystore.path"));
        char[] keyStorePassword = mirthConfig.getString("keystore.storepass").toCharArray();
        char[] keyPassword = mirthConfig.getString("keystore.keypass").toCharArray();
        Provider provider = (Provider) Class.forName(encryptionConfig.getSecurityProvider()).newInstance();

        KeyStore keyStore = null;

        // if the current server version is pre-2.2, load the keystore as JKS
        if (MigrationUtil.compareVersions("2.2.0", getServerVersion()) == 1) {
            keyStore = KeyStore.getInstance("JKS");
        } else {
            keyStore = KeyStore.getInstance("JCEKS");
        }

        if (keyStoreFile.exists()) {
            keyStore.load(new FileInputStream(keyStoreFile), keyStorePassword);
            logger.debug("found and loaded keystore: " + keyStoreFile.getAbsolutePath());
        } else {
            keyStore.load(null, keyStorePassword);
            logger.debug("keystore file not found, created new one");
        }

        configureEncryption(provider, keyStore, keyPassword);
        generateDefaultCertificate(provider, keyStore, keyPassword);

        // write the kesytore back to the file
        FileOutputStream fos = new FileOutputStream(keyStoreFile);
        keyStore.store(fos, keyStorePassword);
        IOUtils.closeQuietly(fos);
    } catch (Exception e) {
        logger.error("Could not initialize security settings.", e);
    }
}

From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java

@Override
public void initializeDatabaseSettings() {
    try {// w w  w  . ja  va 2s  .  co m
        databaseConfig = new DatabaseSettings(ConfigurationConverter.getProperties(mirthConfig));

        // dir.base is not included in mirth.properties, so set it manually
        databaseConfig.setDirBase(getBaseDir());

        String password = databaseConfig.getDatabasePassword();

        if (StringUtils.isNotEmpty(password)) {
            ConfigurationController configurationController = ControllerFactory.getFactory()
                    .createConfigurationController();
            EncryptionSettings encryptionSettings = configurationController.getEncryptionSettings();
            Encryptor encryptor = configurationController.getEncryptor();

            if (encryptionSettings.getEncryptProperties()) {
                if (StringUtils.startsWith(password, EncryptionSettings.ENCRYPTION_PREFIX)) {
                    String encryptedPassword = StringUtils.removeStart(password,
                            EncryptionSettings.ENCRYPTION_PREFIX);
                    String decryptedPassword = encryptor.decrypt(encryptedPassword);
                    databaseConfig.setDatabasePassword(decryptedPassword);
                } else if (StringUtils.isNotBlank(password)) {
                    // encrypt the password and write it back to the file
                    String encryptedPassword = EncryptionSettings.ENCRYPTION_PREFIX
                            + encryptor.encrypt(password);
                    mirthConfig.setProperty("database.password", encryptedPassword);

                    /*
                     * Save using a FileOutputStream so that the file will be saved to the
                     * proper location, even if running from the IDE.
                     */
                    File confDir = new File(ControllerFactory.getFactory().createConfigurationController()
                            .getConfigurationDir());
                    OutputStream os = new FileOutputStream(new File(confDir, "mirth.properties"));

                    try {
                        mirthConfig.save(os);
                    } finally {
                        IOUtils.closeQuietly(os);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ninja.utils.MockNinjaProperties.java

@Override
public Properties getAllCurrentNinjaProperties() {
    return ConfigurationConverter.getProperties(configuration);
}

From source file:ninja.utils.NinjaPropertiesImpl.java

public void bindProperties(Binder binder) {
    Names.bindProperties(binder, ConfigurationConverter.getProperties(compositeConfiguration));
}

From source file:ninja.utils.NinjaPropertiesImpl.java

@Override
public Properties getAllCurrentNinjaProperties() {

    return ConfigurationConverter.getProperties(compositeConfiguration);

}

From source file:org.apache.atlas.kafka.KafkaNotification.java

/**
 * Construct a KafkaNotification./*from   www  . j  a  va2  s. c  o m*/
 *
 * @param applicationProperties  the application properties used to configure Kafka
 *
 * @throws AtlasException if the notification interface can not be created
 */
public KafkaNotification(Configuration applicationProperties) throws AtlasException {
    super(applicationProperties);
    Configuration subsetConfiguration = ApplicationProperties.getSubsetConfiguration(applicationProperties,
            PROPERTY_PREFIX);
    properties = ConfigurationConverter.getProperties(subsetConfiguration);
    //override to store offset in kafka
    //todo do we need ability to replay?

    //Override default configs
    properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
            "org.apache.kafka.common.serialization.StringSerializer");
    properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
            "org.apache.kafka.common.serialization.StringSerializer");
    properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
            "org.apache.kafka.common.serialization.StringDeserializer");
    properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
            "org.apache.kafka.common.serialization.StringDeserializer");
    properties.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, "roundrobin");
    properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "smallest");
}

From source file:org.apache.atlas.security.InMemoryJAASConfiguration.java

public static void init(org.apache.commons.configuration.Configuration atlasConfiguration)
        throws AtlasException {
    LOG.debug("==> InMemoryJAASConfiguration.init()");

    if (atlasConfiguration != null && !atlasConfiguration.isEmpty()) {
        Properties properties = ConfigurationConverter.getProperties(atlasConfiguration);
        init(properties);//from  w ww .j  a  v a 2 s . c  o m
    } else {
        throw new AtlasException("Failed to load JAAS application properties: configuration NULL or empty!");
    }

    LOG.debug("<== InMemoryJAASConfiguration.init()");
}

From source file:org.apache.atlas.web.security.AtlasADAuthenticationProvider.java

private void setADProperties() {
    try {/*  ww  w  .j  a v  a  2s  .  c o  m*/

        Configuration configuration = ApplicationProperties.get();
        Properties properties = ConfigurationConverter
                .getProperties(configuration.subset("atlas.authentication.method.ldap.ad"));
        this.adDomain = properties.getProperty("domain");
        this.adURL = properties.getProperty("url");
        this.adBindDN = properties.getProperty("bind.dn");
        this.adBindPassword = properties.getProperty("bind.password");
        this.adUserSearchFilter = properties.getProperty("user.searchfilter");
        this.adBase = properties.getProperty("base.dn");
        this.adReferral = properties.getProperty("referral");
        this.adDefaultRole = properties.getProperty("default.role");

        this.groupsFromUGI = configuration.getBoolean("atlas.authentication.method.ldap.ugi-groups", true);

        if (LOG.isDebugEnabled()) {
            LOG.debug("AtlasADAuthenticationProvider{" + "adURL='" + adURL + '\'' + ", adDomain='" + adDomain
                    + '\'' + ", adBindDN='" + adBindDN + '\'' + ", adUserSearchFilter='" + adUserSearchFilter
                    + '\'' + ", adBase='" + adBase + '\'' + ", adReferral='" + adReferral + '\''
                    + ", adDefaultRole='" + adDefaultRole + '\'' + ", groupsFromUGI=" + groupsFromUGI + '}');
        }

    } catch (Exception e) {
        LOG.error("Exception while setADProperties", e);
    }
}

From source file:org.apache.atlas.web.security.AtlasLdapAuthenticationProvider.java

private void setLdapProperties() {
    try {/*  w w w  . ja v a 2s . c o  m*/
        Configuration configuration = ApplicationProperties.get();
        Properties properties = ConfigurationConverter
                .getProperties(configuration.subset("atlas.authentication.method.ldap"));
        ldapURL = properties.getProperty("url");
        ldapUserDNPattern = properties.getProperty("userDNpattern");
        ldapGroupSearchBase = properties.getProperty("groupSearchBase");
        ldapGroupSearchFilter = properties.getProperty("groupSearchFilter");
        ldapGroupRoleAttribute = properties.getProperty("groupRoleAttribute");
        ldapBindDN = properties.getProperty("bind.dn");
        ldapBindPassword = properties.getProperty("bind.password");
        ldapDefaultRole = properties.getProperty("default.role");
        ldapUserSearchFilter = properties.getProperty("user.searchfilter");
        ldapReferral = properties.getProperty("referral");
        ldapBase = properties.getProperty("base.dn");
        groupsFromUGI = configuration.getBoolean("atlas.authentication.method.ldap.ugi-groups", true);

        if (LOG.isDebugEnabled()) {
            LOG.debug("AtlasLdapAuthenticationProvider{" + "ldapURL='" + ldapURL + '\''
                    + ", ldapUserDNPattern='" + ldapUserDNPattern + '\'' + ", ldapGroupSearchBase='"
                    + ldapGroupSearchBase + '\'' + ", ldapGroupSearchFilter='" + ldapGroupSearchFilter + '\''
                    + ", ldapGroupRoleAttribute='" + ldapGroupRoleAttribute + '\'' + ", ldapBindDN='"
                    + ldapBindDN + '\'' + ", ldapDefaultRole='" + ldapDefaultRole + '\''
                    + ", ldapUserSearchFilter='" + ldapUserSearchFilter + '\'' + ", ldapReferral='"
                    + ldapReferral + '\'' + ", ldapBase='" + ldapBase + '\'' + ", groupsFromUGI="
                    + groupsFromUGI + '}');
        }

    } catch (Exception e) {
        LOG.error("Exception while setLdapProperties", e);
    }

}