use of org.apache.maven.settings.building.SettingsProblem in project karaf by apache.
the class MavenConfigurationSupport method readSettings.
/**
* Reads on demand <code>settings.xml</code> file - without password decryption. Also
* collects declared servers by ID.
* @param settingsFile
*/
protected synchronized Settings readSettings(File settingsFile) throws SettingsBuildingException {
if (!settingsFile.isFile() || !settingsFile.canRead()) {
return null;
}
try {
DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
DefaultSettingsBuilder builder = factory.newInstance();
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setUserSettingsFile(settingsFile);
SettingsBuildingResult result = builder.build(request);
if (result.getProblems().size() > 0) {
for (SettingsProblem problem : result.getProblems()) {
System.err.println(problem);
}
return null;
} else {
Settings settings = result.getEffectiveSettings();
if (settings.getServers() != null) {
for (Server server : settings.getServers()) {
servers.put(server.getId(), server);
}
}
return settings;
}
} catch (Throwable e) {
System.err.println(e.getMessage());
LOG.error(e.getMessage(), e);
throw e;
}
}
use of org.apache.maven.settings.building.SettingsProblem in project fabric8 by jboss-fuse.
the class MavenSettingsDecrypter method decrypt.
public SettingsDecryptionResult decrypt(SettingsDecryptionRequest request) {
List<SettingsProblem> problems = new ArrayList<SettingsProblem>();
List<Server> servers = new ArrayList<Server>();
for (Server server : request.getServers()) {
server = server.clone();
servers.add(server);
try {
server.setPassword(decrypt(server.getPassword()));
} catch (SecDispatcherException e) {
problems.add(new DefaultSettingsProblem("Failed to decrypt password for server " + server.getId() + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
}
try {
server.setPassphrase(decrypt(server.getPassphrase()));
} catch (SecDispatcherException e) {
problems.add(new DefaultSettingsProblem("Failed to decrypt passphrase for server " + server.getId() + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
}
}
List<Proxy> proxies = new ArrayList<Proxy>();
for (Proxy proxy : request.getProxies()) {
proxy = proxy.clone();
proxies.add(proxy);
try {
proxy.setPassword(decrypt(proxy.getPassword()));
} catch (SecDispatcherException e) {
problems.add(new DefaultSettingsProblem("Failed to decrypt password for proxy " + proxy.getId() + ": " + e.getMessage(), Severity.ERROR, "proxy: " + proxy.getId(), -1, -1, e));
}
}
return new MavenSettingsDecryptionResult(servers, proxies, problems);
}
use of org.apache.maven.settings.building.SettingsProblem in project maven-plugins by apache.
the class GitHubDownloader method configureAuthentication.
public void configureAuthentication(SettingsDecrypter decrypter, String githubAPIServerId, Settings settings, Log log) {
boolean configured = false;
List<Server> servers = settings.getServers();
for (Server server : servers) {
if (server.getId().equals(githubAPIServerId)) {
SettingsDecryptionResult result = decrypter.decrypt(new DefaultSettingsDecryptionRequest(server));
for (SettingsProblem problem : result.getProblems()) {
log.error(problem.getMessage(), problem.getException());
}
server = result.getServer();
String user = server.getUsername();
String password = server.getPassword();
this.client.setCredentials(user, password);
configured = true;
break;
}
}
if (!configured) {
log.warn("Can't find server id [" + githubAPIServerId + "] configured in githubAPIServerId.");
}
}
use of org.apache.maven.settings.building.SettingsProblem in project karaf by apache.
the class MavenConfigurationSupport method decryptSettings.
/**
* <p>Decrypts passwords inside correctly read <code>settings.xml</code>. Also tries to decrypt master password.</p>
* <p>Not called implicitly for each action invocation.</p>
*/
private void decryptSettings() throws Exception {
if (mavenSecuritySettings != null && mavenSettings != null) {
masterPassword = cipher.decryptDecorated(mavenSecuritySettings.getMaster(), masterMasterPassword);
DefaultSecDispatcher dispatcher = new DefaultSecDispatcher();
DefaultSettingsDecrypter decrypter = new DefaultSettingsDecrypter(new DefaultSecDispatcher());
try {
dispatcher.setConfigurationFile(securitySettings.value.getAbsolutePath());
Field f = dispatcher.getClass().getDeclaredField("_cipher");
f.setAccessible(true);
f.set(dispatcher, cipher);
f = decrypter.getClass().getDeclaredField("securityDispatcher");
f.setAccessible(true);
f.set(decrypter, dispatcher);
DefaultSettingsDecryptionRequest req = new DefaultSettingsDecryptionRequest(mavenSettings);
SettingsDecryptionResult res = decrypter.decrypt(req);
if (res.getProblems() != null && res.getProblems().size() > 0) {
for (SettingsProblem sp : res.getProblems()) {
System.err.println(sp);
}
}
for (Proxy proxy : res.getProxies()) {
if (!cipher.isEncryptedString(proxy.getPassword())) {
proxyPasswords.put(proxy.getId(), proxy.getPassword());
}
}
for (Server server : res.getServers()) {
if (!cipher.isEncryptedString(server.getPassword())) {
serverPasswords.put(server.getId(), server.getPassword());
}
}
} catch (Throwable t) {
LOG.warn("Can't decrypt " + securitySettings.value, t);
}
}
}
Aggregations