use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project maven by apache.
the class DefaultWagonManager method getProxy.
public 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.SettingsDecryptionResult in project jib by GoogleContainerTools.
the class MavenSettingsServerCredentials method inferAuth.
/**
* Retrieves credentials for {@code registry} from Maven settings.
*
* @param registry the registry
* @return the auth info for the registry, or {@link Optional#empty} if none could be retrieved
*/
@Override
public Optional<AuthProperty> inferAuth(String registry) throws InferredAuthException {
Server server = getServerFromMavenSettings(registry);
if (server == null) {
return Optional.empty();
}
SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
SettingsDecryptionResult result = decrypter.decrypt(request);
// If there are any ERROR or FATAL problems reported, then decryption failed.
for (SettingsProblem problem : result.getProblems()) {
if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
throw new InferredAuthException("Unable to decrypt server(" + registry + ") info from settings.xml: " + problem);
}
}
Server resultServer = result.getServer();
String username = resultServer.getUsername();
String password = resultServer.getPassword();
return Optional.of(new AuthProperty() {
@Override
public String getUsername() {
return username;
}
@Override
public String getPassword() {
return password;
}
@Override
public String getAuthDescriptor() {
return CREDENTIAL_SOURCE;
}
@Override
public String getUsernameDescriptor() {
return CREDENTIAL_SOURCE;
}
@Override
public String getPasswordDescriptor() {
return CREDENTIAL_SOURCE;
}
});
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project quarkus by quarkusio.
the class BootstrapMavenContext method newRepositorySystemSession.
private DefaultRepositorySystemSession newRepositorySystemSession() throws BootstrapMavenException {
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
final Settings settings = getEffectiveSettings();
final List<Mirror> mirrors = settings.getMirrors();
if (mirrors != null && !mirrors.isEmpty()) {
final boolean isBlockedMethodAvailable = mirrorIsBlockedMethodAvailable();
final DefaultMirrorSelector ms = new DefaultMirrorSelector();
for (Mirror m : mirrors) {
if (isBlockedMethodAvailable) {
ms.add(m.getId(), m.getUrl(), m.getLayout(), false, m.isBlocked(), m.getMirrorOf(), m.getMirrorOfLayouts());
} else {
// Maven pre-3.8.x
ms.add(m.getId(), m.getUrl(), m.getLayout(), false, m.getMirrorOf(), m.getMirrorOfLayouts());
}
}
session.setMirrorSelector(ms);
}
final String localRepoPath = getLocalRepo();
session.setLocalRepositoryManager(getRepositorySystem().newLocalRepositoryManager(session, new LocalRepository(localRepoPath)));
session.setOffline(isOffline());
final BootstrapMavenOptions mvnArgs = getCliOptions();
if (!mvnArgs.isEmpty()) {
if (mvnArgs.hasOption(BootstrapMavenOptions.SUPRESS_SNAPSHOT_UPDATES)) {
session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER);
} else if (mvnArgs.hasOption(BootstrapMavenOptions.UPDATE_SNAPSHOTS)) {
session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
}
if (mvnArgs.hasOption(BootstrapMavenOptions.CHECKSUM_FAILURE_POLICY)) {
session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);
} else if (mvnArgs.hasOption(BootstrapMavenOptions.CHECKSUM_WARNING_POLICY)) {
session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
}
}
final DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
decrypt.setProxies(settings.getProxies());
decrypt.setServers(settings.getServers());
final SettingsDecryptionResult decrypted = new SettingsDecrypterImpl().decrypt(decrypt);
if (!decrypted.getProblems().isEmpty() && log.isDebugEnabled()) {
// this is how maven handles these
for (SettingsProblem p : decrypted.getProblems()) {
log.debug(p.getMessage(), p.getException());
}
}
final DefaultProxySelector proxySelector = new DefaultProxySelector();
for (org.apache.maven.settings.Proxy p : decrypted.getProxies()) {
if (p.isActive()) {
proxySelector.add(toAetherProxy(p), p.getNonProxyHosts());
}
}
session.setProxySelector(proxySelector);
final Map<Object, Object> configProps = new LinkedHashMap<>(session.getConfigProperties());
configProps.put(ConfigurationProperties.USER_AGENT, getUserAgent());
configProps.put(ConfigurationProperties.INTERACTIVE, settings.isInteractiveMode());
final DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
for (Server server : decrypted.getServers()) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(server.getUsername()).addPassword(server.getPassword());
authBuilder.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
authSelector.add(server.getId(), authBuilder.build());
if (server.getConfiguration() != null) {
Xpp3Dom dom = (Xpp3Dom) server.getConfiguration();
for (int i = dom.getChildCount() - 1; i >= 0; i--) {
Xpp3Dom child = dom.getChild(i);
if ("wagonProvider".equals(child.getName())) {
dom.removeChild(i);
}
}
XmlPlexusConfiguration config = new XmlPlexusConfiguration(dom);
configProps.put("aether.connector.wagon.config." + server.getId(), config);
}
configProps.put("aether.connector.perms.fileMode." + server.getId(), server.getFilePermissions());
configProps.put("aether.connector.perms.dirMode." + server.getId(), server.getDirectoryPermissions());
}
session.setAuthenticationSelector(authSelector);
session.setConfigProperties(configProps);
if (session.getCache() == null) {
session.setCache(new DefaultRepositoryCache());
}
if (workspace != null) {
session.setWorkspaceReader(workspace);
}
if (session.getTransferListener() == null && artifactTransferLogging) {
TransferListener transferListener;
if (mvnArgs.hasOption(BootstrapMavenOptions.NO_TRANSFER_PROGRESS)) {
transferListener = new QuietMavenTransferListener();
} else if (mvnArgs.hasOption(BootstrapMavenOptions.BATCH_MODE)) {
transferListener = new BatchModeMavenTransferListener(System.out);
} else {
transferListener = new ConsoleMavenTransferListener(System.out, true);
}
session.setTransferListener(transferListener);
}
return session;
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project flutter-maven-plugin by BlackBeltTechnology.
the class MojoUtils method decryptProxy.
private static Proxy decryptProxy(Proxy proxy, SettingsDecrypter decrypter) {
final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(proxy);
SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
return decryptedResult.getProxy();
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project flutter-maven-plugin by BlackBeltTechnology.
the class MojoUtils method decryptServer.
public static Server decryptServer(String serverId, MavenSession mavenSession, SettingsDecrypter decrypter) {
if (StringUtils.isEmpty(serverId)) {
return null;
}
Server server = mavenSession.getSettings().getServer(serverId);
if (server != null) {
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;
}
}
Aggregations