use of org.apache.commons.configuration.ConfigurationException in project whirr by apache.
the class ClusterSpec method checkAndSetKeyPair.
protected void checkAndSetKeyPair() throws ConfigurationException {
String pairRepresentation = "";
try {
String privateKeyPath = getString(Property.PRIVATE_KEY_FILE);
String publicKeyPath = getString(Property.PUBLIC_KEY_FILE);
publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ? privateKeyPath + ".pub" : publicKeyPath;
if (privateKeyPath != null && publicKeyPath != null) {
pairRepresentation = "(" + privateKeyPath + ", " + publicKeyPath + ")";
KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
if (pair.isEncrypted()) {
throw new ConfigurationException("Key pair " + pairRepresentation + " is encrypted. Try generating a new passwordless SSH keypair " + "(e.g. with ssh-keygen).");
}
if (!sameKeyPair(new File(privateKeyPath), new File(publicKeyPath))) {
throw new ConfigurationException("Both keys should belong " + "to the same key pair: " + pairRepresentation);
}
setPrivateKey(new File(privateKeyPath));
setPublicKey(new File(publicKeyPath));
}
} catch (JSchException e) {
throw new ConfigurationException("Invalid key pair: " + pairRepresentation, e);
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Invalid key: " + pairRepresentation, e);
} catch (IOException e) {
throw new ConfigurationException("Error reading one of key file: " + pairRepresentation, e);
}
}
use of org.apache.commons.configuration.ConfigurationException in project whirr by apache.
the class YarnNodeManagerHandler method beforeConfigure.
@Override
protected void beforeConfigure(ClusterActionEvent event) throws IOException, InterruptedException {
ClusterSpec clusterSpec = event.getClusterSpec();
Configuration conf = getConfiguration(clusterSpec);
Cluster cluster = event.getCluster();
Set<Instance> nodeManagers = cluster.getInstancesMatching(role(ROLE));
if (!nodeManagers.isEmpty()) {
for (Instance nodeManager : nodeManagers) {
event.getFirewallManager().addRules(Rule.create().destination(nodeManager).ports(NODE_MANAGER_WEB_UI_PORT));
}
}
handleFirewallRules(event);
try {
event.getStatementBuilder().addStatements(build("/tmp/yarn-site.xml", clusterSpec, cluster, ROLE));
} catch (ConfigurationException e) {
throw new IOException(e);
}
addStatement(event, call(getConfigureFunction(conf)));
addStatement(event, call(getStartFunction(conf), "nodemanager"));
}
use of org.apache.commons.configuration.ConfigurationException 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");
}
}
}
}
use of org.apache.commons.configuration.ConfigurationException 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));
}
use of org.apache.commons.configuration.ConfigurationException in project sakuli by ConSol.
the class SakuliPropertyPlaceholderConfigurer method modifySahiProxyPortPropertiesConfiguration.
/**
* writes the {@link SahiProxyProperties#PROXY_PORT} value as {@link SahiProxyProperties#SAHI_PROPERTY_PROXY_PORT_MAPPING}
* property to sahiConfigPropertyFilePath!
*/
protected void modifySahiProxyPortPropertiesConfiguration(String sahiConfigPropertyFilePath, Properties props) {
final String sahiProxyPort = props.getProperty(SahiProxyProperties.PROXY_PORT);
if (sahiProxyPort != null) {
try {
PropertiesConfiguration propConfig = new PropertiesConfiguration(sahiConfigPropertyFilePath);
propConfig.setAutoSave(true);
final String sahiMappingPropertyProxyPort = SahiProxyProperties.SAHI_PROPERTY_PROXY_PORT_MAPPING;
if (propConfig.containsKey(sahiMappingPropertyProxyPort)) {
propConfig.clearProperty(sahiMappingPropertyProxyPort);
}
// remove property after the test execution, so that the installation can't break
addToModifiedPropertiesMap(sahiConfigPropertyFilePath, sahiMappingPropertyProxyPort, null);
propConfig.addProperty(sahiMappingPropertyProxyPort, sahiProxyPort);
logger.debug("modify properties file '{}' with '{}={}'", sahiConfigPropertyFilePath, sahiMappingPropertyProxyPort, sahiProxyPort);
} catch (ConfigurationException e) {
logger.error("modify sahi properties went wrong", e);
}
}
}
Aggregations