Search in sources :

Example 26 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project opennms by OpenNMS.

the class ReadOnlyRtConfigDao method getProperties.

/**
	 * Retrieves the properties defined in the rt.properties file.
	 * 
	 * @return a <code>java.util.Properties</code> object containing rt plugin defined properties
	 * 
	 * @author <a href="mailto:jonathan@opennms.org">Jonathan Sartin</a>
	 * 
	 */
protected Configuration getProperties() {
    final long now = System.currentTimeMillis();
    if (m_config == null || now > (m_lastUpdated + TIMEOUT)) {
        String propsFile = getFile();
        LOG.debug("loading properties from: {}", propsFile);
        try {
            m_config = new PropertiesConfiguration(propsFile);
            m_lastUpdated = now;
        } catch (final ConfigurationException e) {
            LOG.error("Unable to load RT properties", e);
        }
    }
    return m_config;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 27 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project opennms by OpenNMS.

the class DefaultOtrsConfigDao method getProperties.

/**
	 * Retrieves the properties defined in the otrs.properties file.
	 * 
	 * @return a
	 *         <code>java.util.Properties object containing otrs plugin defined properties
	 * @throws IOException 
	 */
private Configuration getProperties() {
    Configuration config = new PropertiesConfiguration();
    String propsFile = null;
    try {
        propsFile = new File(new File(System.getProperty("opennms.home"), "etc"), "otrs.properties").getCanonicalPath();
        LOG.debug("loading properties from: {}", propsFile);
        config = new PropertiesConfiguration(propsFile);
    } catch (final ConfigurationException e) {
        LOG.error("Unable to load properties from {}", propsFile, e);
    } catch (final IOException e) {
        LOG.error("Exception when trying to find OTRS configuration properties from {}", propsFile, e);
    }
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File)

Example 28 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project jangaroo-tools by CoreMedia.

the class PropertyClassGenerator method generate.

@Override
public File generate(File propertiesFile) {
    PropertiesConfiguration p = new PropertiesConfiguration();
    p.setDelimiterParsingDisabled(true);
    Reader r = null;
    try {
        r = new BufferedReader(new InputStreamReader(new FileInputStream(propertiesFile), "UTF-8"));
        p.load(r);
    } catch (IOException e) {
        throw new PropcException("Error while parsing properties file", propertiesFile, e);
    } catch (ConfigurationException e) {
        throw new PropcException("Error while parsing properties file", propertiesFile, e);
    } finally {
        try {
            if (r != null) {
                r.close();
            }
        } catch (IOException e) {
        //not really
        }
    }
    ResourceBundleClass bundle = new ResourceBundleClass(PropcHelper.computeBaseClassName(locations, propertiesFile));
    // Create properties class, which registers itself with the bundle.
    return generateJangarooClass(new PropertiesClass(bundle, PropcHelper.computeLocale(propertiesFile), p, propertiesFile));
}
Also used : InputStreamReader(java.io.InputStreamReader) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ResourceBundleClass(net.jangaroo.properties.model.ResourceBundleClass) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) PropcException(net.jangaroo.properties.api.PropcException) PropertiesClass(net.jangaroo.properties.model.PropertiesClass) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream)

Example 29 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project CloudStack-archive by CloudStack-extras.

the class EncryptionSecretKeyChanger method main.

public static void main(String[] args) {
    List<String> argsList = Arrays.asList(args);
    Iterator<String> iter = argsList.iterator();
    String oldMSKey = null;
    String oldDBKey = null;
    String newMSKey = null;
    String newDBKey = null;
    //Parse command-line args
    while (iter.hasNext()) {
        String arg = iter.next();
        // Old MS Key
        if (arg.equals("-m")) {
            oldMSKey = iter.next();
        }
        // Old DB Key
        if (arg.equals("-d")) {
            oldDBKey = iter.next();
        }
        // New MS Key
        if (arg.equals("-n")) {
            newMSKey = iter.next();
        }
        // New DB Key
        if (arg.equals("-e")) {
            newDBKey = iter.next();
        }
    }
    if (oldMSKey == null || oldDBKey == null) {
        System.out.println("Existing MS secret key or DB secret key is not provided");
        usage();
        return;
    }
    if (newMSKey == null && newDBKey == null) {
        System.out.println("New MS secret key and DB secret are both not provided");
        usage();
        return;
    }
    final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
    final Properties dbProps;
    EncryptionSecretKeyChanger keyChanger = new EncryptionSecretKeyChanger();
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    keyChanger.initEncryptor(encryptor, oldMSKey);
    dbProps = new EncryptableProperties(encryptor);
    PropertiesConfiguration backupDBProps = null;
    System.out.println("Parsing db.properties file");
    try {
        dbProps.load(new FileInputStream(dbPropsFile));
        backupDBProps = new PropertiesConfiguration(dbPropsFile);
    } catch (FileNotFoundException e) {
        System.out.println("db.properties file not found while reading DB secret key" + e.getMessage());
    } catch (IOException e) {
        System.out.println("Error while reading DB secret key from db.properties" + e.getMessage());
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
    String dbSecretKey = null;
    try {
        dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret");
    } catch (EncryptionOperationNotPossibleException e) {
        System.out.println("Failed to decrypt existing DB secret key from db.properties. " + e.getMessage());
        return;
    }
    if (!oldDBKey.equals(dbSecretKey)) {
        System.out.println("Incorrect MS Secret Key or DB Secret Key");
        return;
    }
    System.out.println("Secret key provided matched the key in db.properties");
    final String encryptionType = dbProps.getProperty("db.cloud.encryption.type");
    if (newMSKey == null) {
        System.out.println("No change in MS Key. Skipping migrating db.properties");
    } else {
        if (!keyChanger.migrateProperties(dbPropsFile, dbProps, newMSKey, newDBKey)) {
            System.out.println("Failed to update db.properties");
            return;
        } else {
            //db.properties updated successfully
            if (encryptionType.equals("file")) {
                //update key file with new MS key
                try {
                    FileWriter fwriter = new FileWriter(keyFile);
                    BufferedWriter bwriter = new BufferedWriter(fwriter);
                    bwriter.write(newMSKey);
                    bwriter.close();
                } catch (IOException e) {
                    System.out.println("Failed to write new secret to file. Please update the file manually");
                }
            }
        }
    }
    boolean success = false;
    if (newDBKey == null || newDBKey.equals(oldDBKey)) {
        System.out.println("No change in DB Secret Key. Skipping Data Migration");
    } else {
        EncryptionSecretKeyChecker.initEncryptorForMigration(oldMSKey);
        try {
            success = keyChanger.migrateData(oldDBKey, newDBKey);
        } catch (Exception e) {
            System.out.println("Error during data migration");
            e.printStackTrace();
            success = false;
        }
    }
    if (success) {
        System.out.println("Successfully updated secret key(s)");
    } else {
        System.out.println("Data Migration failed. Reverting db.properties");
        //revert db.properties
        try {
            backupDBProps.save();
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
        if (encryptionType.equals("file")) {
            //revert secret key in file
            try {
                FileWriter fwriter = new FileWriter(keyFile);
                BufferedWriter bwriter = new BufferedWriter(fwriter);
                bwriter.write(oldMSKey);
                bwriter.close();
            } catch (IOException e) {
                System.out.println("Failed to revert to old secret to file. Please update the file manually");
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) IOException(java.io.IOException) EncryptableProperties(org.jasypt.properties.EncryptableProperties) Properties(java.util.Properties) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) BufferedWriter(java.io.BufferedWriter) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EncryptableProperties(org.jasypt.properties.EncryptableProperties) ConfigurationException(org.apache.commons.configuration.ConfigurationException) File(java.io.File)

Example 30 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project cloudstack by apache.

the class EncryptionSecretKeyChanger method main.

public static void main(String[] args) {
    List<String> argsList = Arrays.asList(args);
    Iterator<String> iter = argsList.iterator();
    String oldMSKey = null;
    String oldDBKey = null;
    String newMSKey = null;
    String newDBKey = null;
    //Parse command-line args
    while (iter.hasNext()) {
        String arg = iter.next();
        // Old MS Key
        if (arg.equals("-m")) {
            oldMSKey = iter.next();
        }
        // Old DB Key
        if (arg.equals("-d")) {
            oldDBKey = iter.next();
        }
        // New MS Key
        if (arg.equals("-n")) {
            newMSKey = iter.next();
        }
        // New DB Key
        if (arg.equals("-e")) {
            newDBKey = iter.next();
        }
    }
    if (oldMSKey == null || oldDBKey == null) {
        System.out.println("Existing MS secret key or DB secret key is not provided");
        usage();
        return;
    }
    if (newMSKey == null && newDBKey == null) {
        System.out.println("New MS secret key and DB secret are both not provided");
        usage();
        return;
    }
    final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
    final Properties dbProps;
    EncryptionSecretKeyChanger keyChanger = new EncryptionSecretKeyChanger();
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    keyChanger.initEncryptor(encryptor, oldMSKey);
    dbProps = new EncryptableProperties(encryptor);
    PropertiesConfiguration backupDBProps = null;
    System.out.println("Parsing db.properties file");
    try (FileInputStream db_prop_fstream = new FileInputStream(dbPropsFile)) {
        dbProps.load(db_prop_fstream);
        backupDBProps = new PropertiesConfiguration(dbPropsFile);
    } catch (FileNotFoundException e) {
        System.out.println("db.properties file not found while reading DB secret key" + e.getMessage());
    } catch (IOException e) {
        System.out.println("Error while reading DB secret key from db.properties" + e.getMessage());
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
    String dbSecretKey = null;
    try {
        dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret");
    } catch (EncryptionOperationNotPossibleException e) {
        System.out.println("Failed to decrypt existing DB secret key from db.properties. " + e.getMessage());
        return;
    }
    if (!oldDBKey.equals(dbSecretKey)) {
        System.out.println("Incorrect MS Secret Key or DB Secret Key");
        return;
    }
    System.out.println("Secret key provided matched the key in db.properties");
    final String encryptionType = dbProps.getProperty("db.cloud.encryption.type");
    if (newMSKey == null) {
        System.out.println("No change in MS Key. Skipping migrating db.properties");
    } else {
        if (!keyChanger.migrateProperties(dbPropsFile, dbProps, newMSKey, newDBKey)) {
            System.out.println("Failed to update db.properties");
            return;
        } else {
            //db.properties updated successfully
            if (encryptionType.equals("file")) {
                //update key file with new MS key
                try (FileWriter fwriter = new FileWriter(keyFile);
                    BufferedWriter bwriter = new BufferedWriter(fwriter)) {
                    bwriter.write(newMSKey);
                } catch (IOException e) {
                    System.out.println("Failed to write new secret to file. Please update the file manually");
                }
            }
        }
    }
    boolean success = false;
    if (newDBKey == null || newDBKey.equals(oldDBKey)) {
        System.out.println("No change in DB Secret Key. Skipping Data Migration");
    } else {
        EncryptionSecretKeyChecker.initEncryptorForMigration(oldMSKey);
        try {
            success = keyChanger.migrateData(oldDBKey, newDBKey);
        } catch (Exception e) {
            System.out.println("Error during data migration");
            e.printStackTrace();
            success = false;
        }
    }
    if (success) {
        System.out.println("Successfully updated secret key(s)");
    } else {
        System.out.println("Data Migration failed. Reverting db.properties");
        //revert db.properties
        try {
            backupDBProps.save();
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
        if (encryptionType.equals("file")) {
            //revert secret key in file
            try (FileWriter fwriter = new FileWriter(keyFile);
                BufferedWriter bwriter = new BufferedWriter(fwriter)) {
                bwriter.write(oldMSKey);
            } catch (IOException e) {
                System.out.println("Failed to revert to old secret to file. Please update the file manually");
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) IOException(java.io.IOException) EncryptableProperties(org.jasypt.properties.EncryptableProperties) Properties(java.util.Properties) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) BufferedWriter(java.io.BufferedWriter) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EncryptableProperties(org.jasypt.properties.EncryptableProperties) ConfigurationException(org.apache.commons.configuration.ConfigurationException) File(java.io.File)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)102 File (java.io.File)37 Configuration (org.apache.commons.configuration.Configuration)29 ConfigurationException (org.apache.commons.configuration.ConfigurationException)26 IOException (java.io.IOException)12 Test (org.testng.annotations.Test)11 BeforeClass (org.testng.annotations.BeforeClass)10 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)9 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)8 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 FileInputStream (java.io.FileInputStream)6 URL (java.net.URL)6 ServerQueryExecutorV1Impl (com.linkedin.pinot.core.query.executor.ServerQueryExecutorV1Impl)5 ServerConf (com.linkedin.pinot.server.conf.ServerConf)5 FileNotFoundException (java.io.FileNotFoundException)5 Properties (java.util.Properties)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ServerMetrics (com.linkedin.pinot.common.metrics.ServerMetrics)4 FileBasedInstanceDataManagerConfig (com.linkedin.pinot.core.data.manager.config.FileBasedInstanceDataManagerConfig)4