1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.devops.conga.plugins.aem.maven;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.apache.maven.execution.MavenSession;
27 import org.apache.maven.settings.Proxy;
28 import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
29 import org.apache.maven.settings.crypto.SettingsDecrypter;
30 import org.apache.maven.settings.crypto.SettingsDecryptionResult;
31
32
33
34
35 final class ProxySupport {
36
37 private ProxySupport() {
38
39 }
40
41 static List<io.wcm.tooling.commons.packmgr.Proxy> getMavenProxies(MavenSession mavenSession, SettingsDecrypter decrypter) {
42 if (mavenSession == null ||
43 mavenSession.getSettings() == null ||
44 mavenSession.getSettings().getProxies() == null ||
45 mavenSession.getSettings().getProxies().isEmpty()) {
46 return Collections.emptyList();
47 }
48 else {
49 final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies();
50
51 final List<io.wcm.tooling.commons.packmgr.Proxy> proxies = new ArrayList<>(mavenProxies.size());
52
53 for (Proxy mavenProxy : mavenProxies) {
54 if (mavenProxy.isActive()) {
55 Proxy decryptedMavenProxy = decryptProxy(mavenProxy, decrypter);
56 proxies.add(new io.wcm.tooling.commons.packmgr.Proxy(decryptedMavenProxy.getId(),
57 decryptedMavenProxy.getProtocol(),
58 decryptedMavenProxy.getHost(),
59 decryptedMavenProxy.getPort(),
60 decryptedMavenProxy.getUsername(),
61 decryptedMavenProxy.getPassword(),
62 decryptedMavenProxy.getNonProxyHosts()));
63 }
64 }
65
66 return proxies;
67 }
68 }
69
70 private static Proxy decryptProxy(Proxy proxy, SettingsDecrypter decrypter) {
71 final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(proxy);
72 SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
73 return decryptedResult.getProxy();
74 }
75
76 }