use of org.jdom2.input.SAXBuilder in project gocd by gocd.
the class SvnCommandTest method shouldParsePartlyEncodedUrlAndPath.
@Test
public void shouldParsePartlyEncodedUrlAndPath() {
String output = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + " kind=\"dir\"\n" + " path=\"unit-reports\"\n" + " revision=\"3\">\n" + "<url>svn+ssh://hostname/foo%20bar%20baz/end2end</url>\n" + "<repository>\n" + "<root>svn+ssh://hostname/foo%20bar%20baz</root>\n" + "<uuid>f953918e-915c-4459-8d4c-83860cce9d9a</uuid>\n" + "</repository>\n" + "<commit\n" + " revision=\"1\">\n" + "<author>cceuser</author>\n" + "<date>2008-03-20T04:00:43.976517Z</date>\n" + "</commit>\n" + "</entry>\n" + "</info>";
SvnCommand.SvnInfo svnInfo = new SvnCommand.SvnInfo();
svnInfo.parse(output, new SAXBuilder());
assertThat(svnInfo.getUrl(), is("svn+ssh://hostname/foo%20bar%20baz/end2end"));
assertThat(svnInfo.getPath(), is("/end2end"));
}
use of org.jdom2.input.SAXBuilder in project gocd by gocd.
the class SvnCommandTest method shouldParseEncodedUrlAndPath.
@Test
public void shouldParseEncodedUrlAndPath() {
String output = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + " kind=\"dir\"\n" + " path=\"unit-reports\"\n" + " revision=\"3\">\n" + "<url>file:///C:/Documents%20and%20Settings/cceuser/Local%20Settings/Temp/testSvnRepo-1243722556125/end2end/unit-reports</url>\n" + "<repository>\n" + "<root>file:///C:/Documents%20and%20Settings/cceuser/Local%20Settings/Temp/testSvnRepo-1243722556125/end2end</root>\n" + "<uuid>f953918e-915c-4459-8d4c-83860cce9d9a</uuid>\n" + "</repository>\n" + "<commit\n" + " revision=\"1\">\n" + "<author>cceuser</author>\n" + "<date>2008-03-20T04:00:43.976517Z</date>\n" + "</commit>\n" + "</entry>\n" + "</info>";
SvnCommand.SvnInfo svnInfo = new SvnCommand.SvnInfo();
svnInfo.parse(output, new SAXBuilder());
assertThat(svnInfo.getUrl(), is("file:///C:/Documents%20and%20Settings/cceuser/Local%20Settings/Temp/testSvnRepo-1243722556125/end2end/unit-reports"));
assertThat(svnInfo.getPath(), is("/unit-reports"));
}
use of org.jdom2.input.SAXBuilder in project gocd by gocd.
the class ConfigCipherUpdater method migrate.
public void migrate() {
File cipherFile = systemEnvironment.getCipherFile();
String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(timeProvider.currentTime());
File backupCipherFile = new File(systemEnvironment.getConfigDir(), "cipher.original." + timestamp);
File configFile = new File(systemEnvironment.getCruiseConfigFile());
File backupConfigFile = new File(configFile.getParentFile(), configFile.getName() + ".original." + timestamp);
try {
if (!cipherFile.exists() || !FileUtils.readFileToString(cipherFile, UTF_8).equals(FLAWED_VALUE)) {
return;
}
LOGGER.info("Found unsafe cipher {} on server, Go will make an attempt to rekey", FLAWED_VALUE);
FileUtils.copyFile(cipherFile, backupCipherFile);
LOGGER.info("Old cipher was successfully backed up to {}", backupCipherFile.getAbsoluteFile());
FileUtils.copyFile(configFile, backupConfigFile);
LOGGER.info("Old config was successfully backed up to {}", backupConfigFile.getAbsoluteFile());
byte[] oldCipher = FileUtils.readFileToByteArray(backupCipherFile);
new CipherProvider(systemEnvironment).resetCipher();
byte[] newCipher = FileUtils.readFileToByteArray(cipherFile);
if (new String(newCipher).equals(new String(oldCipher))) {
LOGGER.warn("Unable to generate a new safe cipher. Your cipher is unsafe.");
FileUtils.deleteQuietly(backupCipherFile);
FileUtils.deleteQuietly(backupConfigFile);
return;
}
Document document = new SAXBuilder().build(configFile);
List<String> encryptedAttributes = Arrays.asList("encryptedPassword", "encryptedManagerPassword");
List<String> encryptedNodes = Arrays.asList("encryptedValue");
XPathFactory xPathFactory = XPathFactory.instance();
for (String attributeName : encryptedAttributes) {
XPathExpression<Element> xpathExpression = xPathFactory.compile(String.format("//*[@%s]", attributeName), Filters.element());
List<Element> encryptedPasswordElements = xpathExpression.evaluate(document);
for (Element element : encryptedPasswordElements) {
Attribute encryptedPassword = element.getAttribute(attributeName);
encryptedPassword.setValue(reEncryptUsingNewKey(oldCipher, newCipher, encryptedPassword.getValue()));
LOGGER.debug("Replaced encrypted value at {}", element.toString());
}
}
for (String nodeName : encryptedNodes) {
XPathExpression<Element> xpathExpression = xPathFactory.compile(String.format("//%s", nodeName), Filters.element());
List<Element> encryptedNode = xpathExpression.evaluate(document);
for (Element element : encryptedNode) {
element.setText(reEncryptUsingNewKey(oldCipher, newCipher, element.getValue()));
LOGGER.debug("Replaced encrypted value at {}", element.toString());
}
}
try (FileOutputStream fileOutputStream = new FileOutputStream(configFile)) {
XmlUtils.writeXml(document, fileOutputStream);
}
LOGGER.info("Successfully re-encrypted config");
} catch (Exception e) {
LOGGER.error("Re-keying of cipher failed with error: [{}]", e.getMessage(), e);
if (backupCipherFile.exists()) {
try {
FileUtils.copyFile(backupCipherFile, cipherFile);
} catch (IOException e1) {
LOGGER.error("Could not replace the cipher file [{}] with original one [{}], please do so manually. Error: [{}]", cipherFile.getAbsolutePath(), backupCipherFile.getAbsolutePath(), e.getMessage(), e);
bomb(e1);
}
}
}
}
use of org.jdom2.input.SAXBuilder in project gocd by gocd.
the class HgModificationSplitter method modifications.
public List<Modification> modifications() {
try {
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new StringReader(output));
return parseDOMTree(document);
} catch (Exception e) {
throw ExceptionUtils.bomb("Unable to parse hg log output: " + result.replaceSecretInfo(output), result.smudgedException(e));
}
}
use of org.jdom2.input.SAXBuilder in project gocd by gocd.
the class SvnCommand method parseSvnLog.
private List<Modification> parseSvnLog(String output) {
SAXBuilder builder = getBuilder();
SvnInfo svnInfo = remoteInfo(builder);
return svnLogXmlParser.parse(output, svnInfo.getPath(), builder);
}
Aggregations