use of org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest in project maven-archetype by apache.
the class RemoteCatalogArchetypeDataSource method getProxy.
private ProxyInfo getProxy(String protocol) {
MavenSession session = legacySupport.getSession();
if (session != null && protocol != null) {
MavenExecutionRequest request = session.getRequest();
if (request != null) {
List<Proxy> proxies = request.getProxies();
if (proxies != null) {
for (Proxy proxy : proxies) {
if (proxy.isActive() && protocol.equalsIgnoreCase(proxy.getProtocol())) {
SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
proxy = result.getProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost(proxy.getHost());
proxyInfo.setType(proxy.getProtocol());
proxyInfo.setPort(proxy.getPort());
proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
proxyInfo.setUserName(proxy.getUsername());
proxyInfo.setPassword(proxy.getPassword());
return proxyInfo;
}
}
}
}
}
return null;
}
use of org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest in project frontend-maven-plugin by eirslett.
the class MojoUtils method decryptServer.
static Server decryptServer(String serverId, MavenSession mavenSession, SettingsDecrypter decrypter) {
if (StringUtils.isEmpty(serverId)) {
return null;
}
Server server = mavenSession.getSettings().getServer(serverId);
if (server != null) {
synchronized (server) {
final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(server);
SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
return decryptedResult.getServer();
}
} else {
LOGGER.warn("Could not find server '" + serverId + "' in settings.xml");
return null;
}
}
use of org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest 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