Search in sources :

Example 1 with Proxy

use of org.apache.maven.repository.Proxy in project maven by apache.

the class MavenRepositorySystem method getProxy.

private Proxy getProxy(RepositorySystemSession session, ArtifactRepository repository) {
    if (session != null) {
        ProxySelector selector = session.getProxySelector();
        if (selector != null) {
            RemoteRepository repo = RepositoryUtils.toRepo(repository);
            org.eclipse.aether.repository.Proxy proxy = selector.getProxy(repo);
            if (proxy != null) {
                Proxy p = new Proxy();
                p.setHost(proxy.getHost());
                p.setProtocol(proxy.getType());
                p.setPort(proxy.getPort());
                if (proxy.getAuthentication() != null) {
                    repo = new RemoteRepository.Builder(repo).setProxy(proxy).build();
                    AuthenticationContext authCtx = AuthenticationContext.forProxy(session, repo);
                    p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
                    p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
                    p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
                    p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
                    authCtx.close();
                }
                return p;
            }
        }
    }
    return null;
}
Also used : ProxySelector(org.eclipse.aether.repository.ProxySelector) Proxy(org.apache.maven.repository.Proxy) AuthenticationContext(org.eclipse.aether.repository.AuthenticationContext) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 2 with Proxy

use of org.apache.maven.repository.Proxy in project maven by apache.

the class LegacyRepositorySystem method injectProxy.

public void injectProxy(List<ArtifactRepository> repositories, List<org.apache.maven.settings.Proxy> proxies) {
    if (repositories != null) {
        for (ArtifactRepository repository : repositories) {
            org.apache.maven.settings.Proxy proxy = getProxy(repository, proxies);
            if (proxy != null) {
                SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(proxy);
                SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
                proxy = result.getProxy();
                if (logger.isDebugEnabled()) {
                    for (SettingsProblem problem : result.getProblems()) {
                        logger.debug(problem.getMessage(), problem.getException());
                    }
                }
                Proxy p = new Proxy();
                p.setHost(proxy.getHost());
                p.setProtocol(proxy.getProtocol());
                p.setPort(proxy.getPort());
                p.setNonProxyHosts(proxy.getNonProxyHosts());
                p.setUserName(proxy.getUsername());
                p.setPassword(proxy.getPassword());
                repository.setProxy(p);
            } else {
                repository.setProxy(null);
            }
        }
    }
}
Also used : Proxy(org.apache.maven.repository.Proxy) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) LocalArtifactRepository(org.apache.maven.repository.LocalArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DelegatingLocalArtifactRepository(org.apache.maven.repository.DelegatingLocalArtifactRepository) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 3 with Proxy

use of org.apache.maven.repository.Proxy in project maven by apache.

the class LegacyRepositorySystem method getProxy.

private Proxy getProxy(RepositorySystemSession session, ArtifactRepository repository) {
    if (session != null) {
        ProxySelector selector = session.getProxySelector();
        if (selector != null) {
            RemoteRepository repo = RepositoryUtils.toRepo(repository);
            org.eclipse.aether.repository.Proxy proxy = selector.getProxy(repo);
            if (proxy != null) {
                Proxy p = new Proxy();
                p.setHost(proxy.getHost());
                p.setProtocol(proxy.getType());
                p.setPort(proxy.getPort());
                if (proxy.getAuthentication() != null) {
                    repo = new RemoteRepository.Builder(repo).setProxy(proxy).build();
                    AuthenticationContext authCtx = AuthenticationContext.forProxy(session, repo);
                    p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
                    p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
                    p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
                    p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
                    authCtx.close();
                }
                return p;
            }
        }
    }
    return null;
}
Also used : ProxySelector(org.eclipse.aether.repository.ProxySelector) Proxy(org.apache.maven.repository.Proxy) AuthenticationContext(org.eclipse.aether.repository.AuthenticationContext) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 4 with Proxy

use of org.apache.maven.repository.Proxy in project maven by apache.

the class DefaultUpdateCheckManager method getRepositoryKey.

String getRepositoryKey(ArtifactRepository repository) {
    StringBuilder buffer = new StringBuilder(256);
    Proxy proxy = repository.getProxy();
    if (proxy != null) {
        if (proxy.getUserName() != null) {
            int hash = (proxy.getUserName() + proxy.getPassword()).hashCode();
            buffer.append(hash).append('@');
        }
        buffer.append(proxy.getHost()).append(':').append(proxy.getPort()).append('>');
    }
    // consider the username&password because a repo manager might block artifacts depending on authorization
    Authentication auth = repository.getAuthentication();
    if (auth != null) {
        int hash = (auth.getUsername() + auth.getPassword()).hashCode();
        buffer.append(hash).append('@');
    }
    // consider the URL (instead of the id) as this most closely relates to the contents in the repo
    buffer.append(repository.getUrl());
    return buffer.toString();
}
Also used : Proxy(org.apache.maven.repository.Proxy) Authentication(org.apache.maven.artifact.repository.Authentication)

Aggregations

Proxy (org.apache.maven.repository.Proxy)4 AuthenticationContext (org.eclipse.aether.repository.AuthenticationContext)2 ProxySelector (org.eclipse.aether.repository.ProxySelector)2 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 Authentication (org.apache.maven.artifact.repository.Authentication)1 DelegatingLocalArtifactRepository (org.apache.maven.repository.DelegatingLocalArtifactRepository)1 LocalArtifactRepository (org.apache.maven.repository.LocalArtifactRepository)1 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)1 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)1 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)1 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)1