Search in sources :

Example 1 with FileBasedConfiguration

use of org.apache.commons.configuration2.FileBasedConfiguration in project cas by apereo.

the class CasConfigurationPropertiesEnvironmentManager method savePropertyForStandaloneProfile.

/**
 * Save property for standalone profile.
 *
 * @param pair the pair
 */
@SneakyThrows
public void savePropertyForStandaloneProfile(final Pair<String, String> pair) {
    final File file = getStandaloneProfileConfigurationDirectory();
    final Parameters params = new Parameters();
    final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class).configure(params.properties().setFile(new File(file, getApplicationName() + ".properties")));
    final Configuration config = builder.getConfiguration();
    config.setProperty(pair.getKey(), pair.getValue());
    builder.save();
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) FileBasedConfiguration(org.apache.commons.configuration2.FileBasedConfiguration) FileBasedConfiguration(org.apache.commons.configuration2.FileBasedConfiguration) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) SneakyThrows(lombok.SneakyThrows)

Example 2 with FileBasedConfiguration

use of org.apache.commons.configuration2.FileBasedConfiguration in project ranger by apache.

the class LdapConfig method updateInputPropFile.

public void updateInputPropFile(String ldapUrl, String bindDn, String bindPassword, String userSearchBase, String userSearchFilter, String authUser, String authPass) {
    try {
        Parameters params = new Parameters();
        FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class).configure(params.fileBased().setFileName(CONFIG_FILE));
        FileBasedConfiguration config = builder.getConfiguration();
        // Update properties in memory and update the file as well
        prop.setProperty(LGSYNC_LDAP_URL, ldapUrl);
        prop.setProperty(LGSYNC_LDAP_BIND_DN, bindDn);
        prop.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword);
        prop.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase);
        prop.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter);
        prop.setProperty(AUTH_USERNAME, authUser);
        prop.setProperty(AUTH_PASSWORD, authPass);
        config.setProperty(LGSYNC_LDAP_URL, ldapUrl);
        config.setProperty(LGSYNC_LDAP_BIND_DN, bindDn);
        // config.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword);
        config.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase);
        config.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter);
        config.setProperty(AUTH_USERNAME, authUser);
        // config.setProperty(AUTH_PASSWORD, authPass);
        builder.save();
    } catch (ConfigurationException e) {
        System.out.println("Failed to update " + CONFIG_FILE + ": " + e);
    }
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) FileBasedConfiguration(org.apache.commons.configuration2.FileBasedConfiguration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Aggregations

FileBasedConfiguration (org.apache.commons.configuration2.FileBasedConfiguration)2 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)2 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)2 File (java.io.File)1 SneakyThrows (lombok.SneakyThrows)1 Configuration (org.apache.commons.configuration2.Configuration)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1