use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project spring-boot by spring-projects.
the class MavenSettingsReader method readSettings.
public MavenSettings readSettings() {
Settings settings = loadSettings();
SettingsDecryptionResult decrypted = decryptSettings(settings);
if (!decrypted.getProblems().isEmpty()) {
Log.error("Maven settings decryption failed. Some Maven repositories may be inaccessible");
// Continue - the encrypted credentials may not be used
}
return new MavenSettings(settings, decrypted);
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult 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);
}
}
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project decrypt-maven-plugin by davidmoten.
the class DecryptMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Server server = null;
for (Server s : settings.getServers()) {
if (s.getId().equals(serverId)) {
server = s;
}
}
if (server == null) {
throw new MojoExecutionException("serverId not found in settings: " + serverId);
} else {
SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
SettingsDecryptionResult result = decrypter.decrypt(request);
String password = result.getServer().getPassword();
try {
outputFile.getParentFile().mkdirs();
Files.write(outputFile.toPath(), password.getBytes(Charset.forName("UTF-8")));
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project maven by apache.
the class LegacyRepositorySystem method injectProxy.
public void injectProxy(List<ArtifactRepository> repositories, List<org.apache.maven.settings.Proxy> proxies) {
if (repositories != null) {
for (ArtifactRepository repository : repositories) {
org.apache.maven.settings.Proxy proxy = getProxy(repository, proxies);
if (proxy != null) {
SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(proxy);
SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
proxy = result.getProxy();
if (logger.isDebugEnabled()) {
for (SettingsProblem problem : result.getProblems()) {
logger.debug(problem.getMessage(), problem.getException());
}
}
Proxy p = new Proxy();
p.setHost(proxy.getHost());
p.setProtocol(proxy.getProtocol());
p.setPort(proxy.getPort());
p.setNonProxyHosts(proxy.getNonProxyHosts());
p.setUserName(proxy.getUsername());
p.setPassword(proxy.getPassword());
repository.setProxy(p);
} else {
repository.setProxy(null);
}
}
}
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project maven by apache.
the class LegacyRepositorySystem method injectAuthentication.
public void injectAuthentication(List<ArtifactRepository> repositories, List<Server> servers) {
if (repositories != null) {
Map<String, Server> serversById = new HashMap<>();
if (servers != null) {
for (Server server : servers) {
if (!serversById.containsKey(server.getId())) {
serversById.put(server.getId(), server);
}
}
}
for (ArtifactRepository repository : repositories) {
Server server = serversById.get(repository.getId());
if (server != null) {
SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
server = result.getServer();
if (logger.isDebugEnabled()) {
for (SettingsProblem problem : result.getProblems()) {
logger.debug(problem.getMessage(), problem.getException());
}
}
Authentication authentication = new Authentication(server.getUsername(), server.getPassword());
authentication.setPrivateKey(server.getPrivateKey());
authentication.setPassphrase(server.getPassphrase());
repository.setAuthentication(authentication);
} else {
repository.setAuthentication(null);
}
}
}
}
Aggregations