private static Proxy parseProxyArg(String proxyUrl, String proxyUsername, String proxyPassword) throws MalformedURLException { URL url = new URL(proxyUrl); if (StringUtils.isNotEmpty(proxyUsername) && StringUtils.isNotEmpty(proxyPassword)) { AuthenticationBuilder authBuilder = new AuthenticationBuilder(); authBuilder.addUsername(proxyUsername).addPassword(proxyPassword); return new Proxy(url.getProtocol(), url.getHost(), url.getPort(), authBuilder.build()); } else { return new Proxy(url.getProtocol(), url.getHost(), url.getPort()); } }
p.setHost( proxy.getHost() ); p.setProtocol( proxy.getType() ); p.setPort( proxy.getPort() ); if ( proxy.getAuthentication() != null )
if ( proxy != null ) buffer.append( " via " ).append( proxy.getHost() ).append( ':' ).append( proxy.getPort() ); auth = proxy.getAuthentication(); if ( auth != null )
@Override public Proxy getProxy(RemoteRepository repo) { Proxy ret = null; if (proxy.getType().equals(repo.getProtocol())) { boolean match = false; for (Pattern p : nonProxyHosts) { if (p.matcher(repo.getHost()).matches()) { match = true; break; } } if (!match) { ret = proxy; } } return ret; } }
/** * Gets an authentication context for the proxy of the specified repository. * * @param session The repository system session during which the repository is accessed, must not be {@code null}. * @param repository The repository for whose proxy to create an authentication context, must not be {@code null}. * @return An authentication context for the proxy or {@code null} if no proxy is set or no authentication is * configured for it. */ public static AuthenticationContext forProxy( RepositorySystemSession session, RemoteRepository repository ) { Proxy proxy = repository.getProxy(); return newInstance( session, repository, proxy, ( proxy != null ) ? proxy.getAuthentication() : null ); }
if ( proxy != null ) buffer.append( " via " ).append( proxy.getHost() ).append( ':' ).append( proxy.getPort() ); auth = proxy.getAuthentication(); if ( auth != null )
String key = proxy.proxy.getType().toLowerCase( Locale.ENGLISH ); if ( !candidates.containsKey( key ) )
/** * Gets an authentication context for the proxy of the specified repository. * * @param session The repository system session during which the repository is accessed, must not be {@code null}. * @param repository The repository for whose proxy to create an authentication context, must not be {@code null}. * @return An authentication context for the proxy or {@code null} if no proxy is set or no authentication is * configured for it. */ public static AuthenticationContext forProxy( RepositorySystemSession session, RemoteRepository repository ) { Proxy proxy = repository.getProxy(); return newInstance( session, repository, proxy, ( proxy != null ) ? proxy.getAuthentication() : null ); }
private DefaultTeslaAether createTeslaAether(List<Repository> remoteRepositories) { if (!useProxy) { return new DefaultTeslaAether( localRepository, remoteRepositories.toArray(new Repository[0]) ); } if (!StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTP) && !StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTPS)) { throw new IllegalArgumentException("invalid proxy type: " + proxyType); } RepositorySystemSession repositorySystemSession = new RepositorySystemSessionProvider(new File(localRepository)).get(); List<RemoteRepository> rl = remoteRepositories.stream().map(r -> { RemoteRepository.Builder builder = new RemoteRepository.Builder(r.getId(), "default", r.getUrl()); if (r.getUsername() != null && r.getPassword() != null) { Authentication auth = new AuthenticationBuilder().addUsername(r.getUsername()).addPassword(r.getPassword()).build(); builder.setAuthentication(auth); } final Authentication proxyAuth; if (Strings.isNullOrEmpty(proxyUsername)) { proxyAuth = null; } else { proxyAuth = new AuthenticationBuilder().addUsername(proxyUsername).addPassword(proxyPassword).build(); } builder.setProxy(new Proxy(proxyType, proxyHost, proxyPort, proxyAuth)); return builder.build(); }).collect(Collectors.toList()); return new DefaultTeslaAether(rl, repositorySystemSession); }
p.setHost( proxy.getHost() ); p.setProtocol( proxy.getType() ); p.setPort( proxy.getPort() ); if ( proxy.getAuthentication() != null )
@Test public void testProxies() { String oldSettingsXmlPath = System.getProperty( CUSTOM_SETTINGS_PROPERTY ); try { if (oldSettingsXmlPath != null) { System.clearProperty( CUSTOM_SETTINGS_PROPERTY ); } MavenSettings.reinitSettingsFromString( SETTINGS_WITH_PROXY ); Aether aether = Aether.getAether(); RemoteRepository remoteRepository = new RemoteRepository.Builder( "local", "default", "http://myserver.com" ).build(); Proxy proxy = aether.getSession().getProxySelector().getProxy( remoteRepository ); assertEquals("http", proxy.getType()); assertEquals("localhost", proxy.getHost()); assertEquals(8888, proxy.getPort()); } finally { if (oldSettingsXmlPath != null) { System.setProperty( CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath ); } MavenSettings.reinitSettings(); } }
String key = proxy.proxy.getType().toLowerCase( Locale.ENGLISH ); if ( !candidates.containsKey( key ) )
/** * Gets the fingerprint for the authentication of the specified repository's proxy. * * @param session The repository system session during which the fingerprint is requested, must not be {@code null}. * @param repository The repository whose proxy authentication is to be fingerprinted, must not be {@code null}. * @return The fingerprint of the proxy authentication or an empty string if no proxy is present or if no proxy * authentication is configured, never {@code null}. */ public static String forProxy( RepositorySystemSession session, RemoteRepository repository ) { String digest = ""; Proxy proxy = repository.getProxy(); if ( proxy != null ) { Authentication auth = proxy.getAuthentication(); if ( auth != null ) { AuthenticationDigest authDigest = new AuthenticationDigest( session, repository, proxy ); auth.digest( authDigest ); digest = authDigest.digest(); } } return digest; }
private static Proxy toProxy( org.apache.maven.repository.Proxy proxy ) { Proxy result = null; if ( proxy != null ) { AuthenticationBuilder authBuilder = new AuthenticationBuilder(); authBuilder.addUsername( proxy.getUserName() ).addPassword( proxy.getPassword() ); result = new Proxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), authBuilder.build() ); } return result; }
private String getRepoKey(RepositorySystemSession session, RemoteRepository repository) { StringBuilder buffer = new StringBuilder(128); Proxy proxy = repository.getProxy(); if (proxy != null) { buffer.append(AuthenticationDigest.forProxy(session, repository)).append('@'); buffer.append(proxy.getHost()).append(':').append(proxy.getPort()).append('>'); } buffer.append(AuthenticationDigest.forRepository(session, repository)).append('@'); buffer.append(repository.getContentType()).append('-'); buffer.append(normalizeRepoUrl(repository.getUrl())); return buffer.toString(); }