static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) { if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) { return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList()); } else { final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies(); final List<ProxyConfig.Proxy> proxies = new ArrayList<ProxyConfig.Proxy>(mavenProxies.size()); for (Proxy mavenProxy : mavenProxies) { if (mavenProxy.isActive()) { mavenProxy = decryptProxy(mavenProxy, decrypter); proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(), mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts())); } } LOGGER.info("Found proxies: {}", proxies); return new ProxyConfig(proxies); } }
/** * Returns the maven proxy. * * @return the maven proxy */ private Proxy getMavenProxy() { if (mavenSettings != null) { final List<Proxy> proxies = mavenSettings.getProxies(); if (proxies != null && !proxies.isEmpty()) { if (mavenSettingsProxyId != null) { for (Proxy proxy : proxies) { if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) { return proxy; } } } else { for (Proxy aProxy : proxies) { if (aProxy.isActive()) { return aProxy; } } } } } return null; }
server = server.clone(); server.setPassword( decrypt( server.getPassword() ) ); proxy = proxy.clone(); proxy.setPassword( decrypt( proxy.getPassword() ) ); problems.add( new DefaultSettingsProblem( "Failed to decrypt password for proxy " + proxy.getId() + ": " + e.getMessage(), Severity.ERROR, "proxy: " + proxy.getId(), -1, -1, e ) );
authBuilder.addUsername( proxy.getUsername() ).addPassword( proxy.getPassword() ); proxySelector.add( new org.eclipse.aether.repository.Proxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), authBuilder.build() ), proxy.getNonProxyHosts() ); authBuilder.addUsername( server.getUsername() ).addPassword( server.getPassword() ); authBuilder.addPrivateKey( server.getPrivateKey(), server.getPassphrase() ); authSelector.add( server.getId(), authBuilder.build() );
for (Mirror m : _settings.getMirrors()) { mirrorSelector.add(m.getId(), m.getUrl(), m.getLayout(), false, m.getMirrorOf(), m.getMirrorOfLayouts()); DefaultProxySelector proxySelector = new DefaultProxySelector(); for (Proxy p : decryptionResult.getProxies()) { if (p.isActive()) { proxySelector.add(new org.sonatype.aether.repository.Proxy(p.getProtocol(), p.getHost(), p.getPort(), new Authentication(p.getUsername(), p.getPassword())), p.getNonProxyHosts()); DefaultAuthenticationSelector authenticationSelector = new DefaultAuthenticationSelector(); for (Server s : decryptionResult.getServers()) { authenticationSelector.add(s.getId(), new Authentication(s.getUsername(), s.getPassword(), s.getPrivateKey(), s.getPassphrase()));
public IProxyFactory getProxyFactory(Settings settings) { URI downloadUri = URI.create(downloadPath); final String downloadHost = downloadUri.getHost(); final String downloadProto = downloadUri.getScheme(); if (settings.getProxies() != null) { for (org.apache.maven.settings.Proxy proxy : (List<org.apache.maven.settings.Proxy>) settings.getProxies()) { if (proxy.isActive() && equalsIgnoreCase(proxy.getProtocol(), downloadProto) && !contains(proxy.getNonProxyHosts(), downloadHost)) { return new HttpProxyFactory(proxy.getHost(), proxy.getPort()); } } } return new NoProxyFactory(); }
request.setOffline( settings.isOffline() ); request.setInteractiveMode( settings.isInteractiveMode() ); request.setPluginGroups( settings.getPluginGroups() ); request.setLocalRepositoryPath( settings.getLocalRepository() ); for ( Server server : settings.getServers() ) server = server.clone(); for ( Proxy proxy : settings.getProxies() ) if ( !proxy.isActive() ) proxy = proxy.clone();
settings.setString(Settings.KEYS.PROXY_SERVER, proxy.getHost()); settings.setString(Settings.KEYS.PROXY_PORT, Integer.toString(proxy.getPort())); final String userName = proxy.getUsername(); final String password = proxy.getPassword(); settings.setStringIfNotNull(Settings.KEYS.PROXY_USERNAME, userName); settings.setStringIfNotNull(Settings.KEYS.PROXY_PASSWORD, password); settings.setStringIfNotNull(Settings.KEYS.PROXY_NON_PROXY_HOSTS, proxy.getNonProxyHosts()); || (ex.getCause() != null && ex.getCause().getCause() instanceof FileNotFoundException)) { final String tmp = server.getPassword(); if (tmp.startsWith("{") && tmp.endsWith("}")) { getLog().error(String.format( if (Boolean.TRUE.equals(artifactoryAnalyzerEnabled)) { if (artifactoryAnalyzerServerId != null) { final Server server = settingsXml.getServer(artifactoryAnalyzerServerId); if (server != null) { settings.setStringIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_API_USERNAME, server.getUsername()); settings.setStringIfNotNull(Settings.KEYS.ANALYZER_ARTIFACTORY_API_TOKEN, server.getPassword()); settings.setStringIfNotEmpty(Settings.KEYS.DB_CONNECTION_STRING, connectionString); if (databaseUser == null && databasePassword == null && serverId != null) { final Server server = settingsXml.getServer(serverId); if (server != null) { databaseUser = server.getUsername();
final Map<Protocol, ProxyInfo> proxyInfos = new HashMap<Protocol, ProxyInfo>(1); if (server != null && server.getUsername() != null) { log.info(" + Using server credentials \"{}\" from Maven settings.", server.getId()); authenticationInfo = new UsernamePasswordAuthenticationInfo(server.getUsername(), server.getPassword()); if (proxy.getUsername() != null) { proxyAuthentication = new UsernamePasswordAuthenticationInfo(proxy.getUsername(), proxy.getPassword()); log.info(" + Using \"{}\" {} Proxy from Maven settings.", proxy.getId(), proxy.getProtocol().toUpperCase()); final ProxyInfo zProxy = new ProxyInfo(baseUrl.getProtocol(), proxy.getHost(), proxy.getPort(), proxyAuthentication); proxyInfos.put(zProxy.getProxyProtocol(), zProxy);
MavenMvnSettings(MavenConfig config, RepositorySystem repoSystem, RepositoryListener listener) throws ArtifactException { Settings settings = buildMavenSettings(config.getSettings()); repositories = Collections.unmodifiableList(buildRemoteRepositories(settings)); Proxy proxy = settings.getActiveProxy(); MavenProxySelector proxySelector = null; if (proxy != null) { MavenProxySelector.Builder builder = new MavenProxySelector.Builder(proxy.getHost(), proxy.getPort(), proxy.getProtocol()); builder.setPassword(proxy.getPassword()); builder.setUserName(proxy.getUsername()); if (proxy.getNonProxyHosts() != null) { String[] hosts = proxy.getNonProxyHosts().split("\\|"); builder.addNonProxyHosts(Arrays.asList(hosts)); } proxySelector = builder.build(); } session = Util.newRepositorySession(repoSystem, settings.getLocalRepository() == null ? config.getLocalRepository() : Paths.get(settings.getLocalRepository()), listener, proxySelector, settings.isOffline()); }
/** * Uploads the {@code sourceDirectory} to the {@code deployUrl} as a "whole". This means, that the "image" * (sourceDirectory) should be already prepared, as there will be no transformations applied to them, content and * filenames will be deploy as-is. */ protected void zapUp(final Server server, final Proxy proxy, final File sourceDirectory, final String deployUrl) throws IOException { final ZapperRequest request = new ZapperRequest(sourceDirectory, deployUrl); if (server != null) { request.setRemoteUsername(server.getUsername()); request.setRemotePassword(server.getPassword()); } if (proxy != null) { request.setProxyProtocol("http"); // Proxy is always HTTP request.setProxyHost(proxy.getHost()); request.setProxyPort(proxy.getPort()); request.setProxyUsername(proxy.getUsername()); request.setProxyPassword(proxy.getPassword()); } zapper.deployDirectory(request); }
@Override public void validate( Settings settings, SettingsProblemCollector problems ) if ( settings.isUsePluginRegistry() ) List<String> pluginGroups = settings.getPluginGroups(); List<Server> servers = settings.getServers(); validateStringNotEmpty( problems, "servers.server[" + i + "].id", server.getId(), null ); if ( !serverIds.add( server.getId() ) ) "must be unique but found duplicate server with id " + server.getId() ); if ( !proxyIds.add( proxy.getId() ) ) "must be unique but found duplicate proxy with id " + proxy.getId() ); validateStringNotEmpty( problems, "proxies.proxy.host", proxy.getHost(), proxy.getId() );
manager = new TomcatManager( url, userName, password, charset, settings.isInteractiveMode() ); manager.setUserAgent( name + "/" + version ); Proxy proxy = session.getSettings().getActiveProxy(); if ( proxy != null && proxy.isActive() ) getLog().debug( "proxy: " + proxy.getHost() + ":" + proxy.getPort() ); manager.setProxy( proxy );
Proxy proxy = settings.getActiveProxy(); if (proxy.getHost() == null) { throw new SettingsConfigurationException("Proxy in settings.xml has no host"); for (Server server : (List<Server>)settings.getServers()) { if (server.getConfiguration() != null) { for (Mirror mirror : (List<Mirror>)settings.getMirrors()) {
for ( Server server : encryptedSettings.getServers() ) String password = server.getPassword(); if ( password != null && !isEncryptedString( password ) ) server.setPassword( encryptAndDecorate( password ) ); String passphrase = server.getPassphrase(); if ( passphrase != null && !isEncryptedString( passphrase ) ) for ( Proxy proxy : encryptedSettings.getProxies() ) String password = proxy.getPassword(); if ( password != null && !isEncryptedString( password ) ) proxy.setPassword( encryptAndDecorate( password ) );
for (final org.apache.maven.settings.Proxy maven_proxy : settings.getProxies()) { if (!maven_proxy.isActive()) { log.debug(new StringBuilder(32) .append("proxy ") .append(maven_proxy.getId()) .append(" is not active, ignoring") .toString()); final String proxy_protocol = maven_proxy.getProtocol(); if (!Objects.equals(proxy_protocol, target_protocol)) { log.debug(new StringBuilder(32) .append("proxy ") .append(maven_proxy.getId()) .append(" protocol ") .append(proxy_protocol) .append(maven_proxy.getId()) .append(" as http/https proxy") .toString()); Proxy.Type.HTTP, InetSocketAddress.createUnresolved( maven_proxy.getHost(), maven_proxy.getPort()));
private Proxy getProxyFromSettings() throws MojoExecutionException { if (settings == null) { return null; } if (proxyId != null) { for (Proxy proxy : settings.getProxies()) { if (proxyId.equals(proxy.getId())) { return proxy; } } throw new MojoExecutionException("Configured proxy with id=" + proxyId + " not found"); } // Get active http/https proxy for (Proxy proxy : settings.getProxies()) { if (proxy.isActive() && ("http".equalsIgnoreCase(proxy.getProtocol()) || "https".equalsIgnoreCase(proxy.getProtocol()))) { return proxy; } } return null; }
/* default */ static Proxy getProxy(MavenSession mavenSession, SettingsDecrypter decrypter) { if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) { LOGGER.info("Proxy is not specified."); return null; } else { final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies(); for (Proxy proxy : mavenProxies) { if (proxy.isActive()) { proxy = decryptProxy(proxy, decrypter); try (Socket socket = new Socket(proxy.getHost(), proxy.getPort())) { } catch (IOException e) { LOGGER.info(String.format("Proxy: %s:%s is not available", proxy.getHost(), proxy.getPort())); continue; } LOGGER.info(String.format("Found proxy: %s:%s", proxy.getHost(), proxy.getPort())); return proxy; } } LOGGER.info("No active proxies found."); return null; } }
if (!cipher.isEncryptedString(proxy.getPassword())) { proxyPasswords.put(proxy.getId(), proxy.getPassword()); if (!cipher.isEncryptedString(server.getPassword())) { serverPasswords.put(server.getId(), server.getPassword());
private void addProxyOption(final List<String> args) { if (isNotEmpty(proxy)) { addStringOption(args, "--proxy=", proxy); } else if (hasServerSettings()) { final Proxy activCfgProxy = settings.getActiveProxy(); if (activCfgProxy != null) { addStringOption(args, "--proxy=", activCfgProxy.getHost() + ":" + activCfgProxy.getPort()); } } }