Search in sources :

Example 31 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project incubator-atlas by apache.

the class BaseSecurityTest method writeConfiguration.

public static String writeConfiguration(final PropertiesConfiguration configuration) throws Exception {
    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
        url = BaseSecurityTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
        url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    PropertiesConfiguration configuredProperties = new PropertiesConfiguration();
    configuredProperties.load(url);
    configuredProperties.copy(configuration);
    String persistDir = TestUtils.getTempDirectory();
    configuredProperties.setProperty("atlas.authentication.method.file", "true");
    configuredProperties.setProperty("atlas.authentication.method.file.filename", persistDir + "/users-credentials");
    configuredProperties.setProperty("atlas.auth.policy.file", persistDir + "/policy-store.txt");
    TestUtils.writeConfiguration(configuredProperties, persistDir + File.separator + ApplicationProperties.APPLICATION_PROPERTIES);
    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);
    ApplicationProperties.forceReload();
    return persistDir;
}
Also used : File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) URL(java.net.URL)

Example 32 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project incubator-atlas by apache.

the class SecureEmbeddedServerTestBase method testMissingEntriesInCredentialProvider.

@Test
public void testMissingEntriesInCredentialProvider() throws Exception {
    // setup the configuration
    final PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
    try {
        secureEmbeddedServer = new SecureEmbeddedServer(securePort, TestUtils.getWarPath()) {

            @Override
            protected PropertiesConfiguration getConfiguration() {
                return configuration;
            }
        };
        Assert.fail("No entries should generate an exception");
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().startsWith("No credential entry found for"));
    } finally {
        secureEmbeddedServer.server.stop();
    }
}
Also used : IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.testng.annotations.Test)

Example 33 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project incubator-atlas by apache.

the class AtlasAuthenticationSimpleFilterTest method generateSimpleLoginConfiguration.

protected String generateSimpleLoginConfiguration() throws Exception {
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setProperty("atlas.http.authentication.enabled", "true");
    config.setProperty("atlas.http.authentication.type", "simple");
    return writeConfiguration(config);
}
Also used : PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 34 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project incubator-atlas by apache.

the class AdminJerseyResourceIT method testGetVersion.

@Test
public void testGetVersion() throws Exception {
    JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.VERSION, null, (String[]) null);
    Assert.assertNotNull(response);
    PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
    Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version"));
    Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name"));
    Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.testng.annotations.Test)

Example 35 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)118 File (java.io.File)38 Configuration (org.apache.commons.configuration.Configuration)33 ConfigurationException (org.apache.commons.configuration.ConfigurationException)33 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 FileInputStream (java.io.FileInputStream)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 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 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4