File file = new File(settingsFile);
if (!file.canWrite()) {
file = new File(new File(System.getProperty("user.home", ".")), DEFAULT_SETTINGS_FILE);
}
SoapuiSettingsDocumentConfig settingsDocument = (SoapuiSettingsDocumentConfig) this.settingsDocument.copy();
String password = settings.getString(SecuritySettings.SHADOW_PASSWORD, null);
if (password != null && password.length() > 0) {
try {
byte[] data = settingsDocument.xmlText().getBytes();
String encryptionAlgorithm = "des3";
byte[] encryptedData = OpenSSL.encrypt(encryptionAlgorithm, password.toCharArray(), data);
settingsDocument.setSoapuiSettings(null);
settingsDocument.getSoapuiSettings().setEncryptedContent(encryptedData);
settingsDocument.getSoapuiSettings().setEncryptedContentAlgorithm(encryptionAlgorithm);
} catch (UnsupportedEncodingException e) {
log.error("Encryption error", e);
} catch (IOException e) {
log.error("Encryption error", e);
} catch (GeneralSecurityException e) {
log.error("Encryption error", e);
}
}
FileOutputStream out = new FileOutputStream(file);
settingsDocument.save(out);
out.flush();
out.close();
log.info("Settings saved to [" + file.getAbsolutePath() + "]");
lastSettingsLoad = file.lastModified();
return file.getAbsolutePath();