Search in sources :

Example 1 with Authentication

use of org.sonatype.aether.repository.Authentication in project zeppelin by apache.

the class AbstractDependencyResolver method setProxy.

public void setProxy(URL proxyUrl, String proxyUser, String proxyPassword) {
    Authentication auth = new Authentication(proxyUser, proxyPassword);
    Proxy proxy = new Proxy(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort(), auth);
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            repo.setProxy(proxy);
        }
    }
}
Also used : Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication) RemoteRepository(org.sonatype.aether.repository.RemoteRepository)

Example 2 with Authentication

use of org.sonatype.aether.repository.Authentication in project gradle by gradle.

the class MavenDeployAction method createRepository.

private org.sonatype.aether.repository.RemoteRepository createRepository(RemoteRepository gradleRepo) {
    org.sonatype.aether.repository.RemoteRepository repo = new org.sonatype.aether.repository.RemoteRepository("remote", gradleRepo.getLayout(), gradleRepo.getUrl());
    org.apache.maven.artifact.ant.Authentication auth = gradleRepo.getAuthentication();
    if (auth != null) {
        repo.setAuthentication(new Authentication(auth.getUserName(), auth.getPassword(), auth.getPrivateKey(), auth.getPassphrase()));
    }
    org.apache.maven.artifact.ant.Proxy proxy = gradleRepo.getProxy();
    if (proxy != null) {
        DefaultProxySelector proxySelector = new DefaultProxySelector();
        Authentication proxyAuth = new Authentication(proxy.getUserName(), proxy.getPassword());
        proxySelector.add(new Proxy(proxy.getType(), proxy.getHost(), proxy.getPort(), proxyAuth), proxy.getNonProxyHosts());
        repo.setProxy(proxySelector.getProxy(repo));
    }
    return repo;
}
Also used : DefaultProxySelector(org.sonatype.aether.util.repository.DefaultProxySelector) RemoteRepository(org.apache.maven.artifact.ant.RemoteRepository) Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication)

Example 3 with Authentication

use of org.sonatype.aether.repository.Authentication in project sonatype-aether by sonatype.

the class DefaultRemoteRepositoryManagerTest method testMirrorAuthentication.

@Test
public void testMirrorAuthentication() {
    final RemoteRepository repo = newRepo("a", "http://", false, "", "");
    final RemoteRepository mirror = newRepo("a", "http://", false, "", "");
    mirror.setAuthentication(new Authentication("username", "password"));
    session.setMirrorSelector(new MirrorSelector() {

        public RemoteRepository getMirror(RemoteRepository repository) {
            return mirror;
        }
    });
    List<RemoteRepository> result = manager.aggregateRepositories(session, Collections.<RemoteRepository>emptyList(), Arrays.asList(repo), true);
    assertEquals(1, result.size());
    assertEquals("username", result.get(0).getAuthentication().getUsername());
    assertEquals("password", result.get(0).getAuthentication().getPassword());
}
Also used : Authentication(org.sonatype.aether.repository.Authentication) MirrorSelector(org.sonatype.aether.repository.MirrorSelector) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 4 with Authentication

use of org.sonatype.aether.repository.Authentication in project sonatype-aether by sonatype.

the class DefaultRemoteRepositoryManager method aggregateRepositories.

public List<RemoteRepository> aggregateRepositories(RepositorySystemSession session, List<RemoteRepository> dominantRepositories, List<RemoteRepository> recessiveRepositories, boolean recessiveIsRaw) {
    if (recessiveRepositories.isEmpty()) {
        return dominantRepositories;
    }
    MirrorSelector mirrorSelector = session.getMirrorSelector();
    AuthenticationSelector authSelector = session.getAuthenticationSelector();
    ProxySelector proxySelector = session.getProxySelector();
    List<RemoteRepository> result = new ArrayList<RemoteRepository>(dominantRepositories);
    next: for (RemoteRepository recessiveRepository : recessiveRepositories) {
        RemoteRepository repository = recessiveRepository;
        if (recessiveIsRaw) {
            RemoteRepository mirrorRepository = mirrorSelector.getMirror(recessiveRepository);
            if (mirrorRepository == null) {
                repository = recessiveRepository;
            } else {
                logger.debug("Using mirror " + mirrorRepository.getId() + " (" + mirrorRepository.getUrl() + ") for " + recessiveRepository.getId() + " (" + recessiveRepository.getUrl() + ").");
                repository = mirrorRepository;
            }
        }
        String key = getKey(repository);
        for (ListIterator<RemoteRepository> it = result.listIterator(); it.hasNext(); ) {
            RemoteRepository dominantRepository = it.next();
            if (key.equals(getKey(dominantRepository))) {
                if (!dominantRepository.getMirroredRepositories().isEmpty() && !repository.getMirroredRepositories().isEmpty()) {
                    RemoteRepository mergedRepository = mergeMirrors(session, dominantRepository, repository);
                    if (mergedRepository != dominantRepository) {
                        it.set(mergedRepository);
                    }
                }
                continue next;
            }
        }
        if (recessiveIsRaw) {
            Authentication auth = authSelector.getAuthentication(repository);
            if (auth != null) {
                repository.setAuthentication(auth);
            }
            Proxy proxy = proxySelector.getProxy(repository);
            if (proxy != null) {
                repository.setProxy(proxy);
            }
        }
        result.add(repository);
    }
    return result;
}
Also used : ProxySelector(org.sonatype.aether.repository.ProxySelector) Proxy(org.sonatype.aether.repository.Proxy) AuthenticationSelector(org.sonatype.aether.repository.AuthenticationSelector) MirrorSelector(org.sonatype.aether.repository.MirrorSelector) Authentication(org.sonatype.aether.repository.Authentication) ArrayList(java.util.ArrayList) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ListIterator(java.util.ListIterator)

Example 5 with Authentication

use of org.sonatype.aether.repository.Authentication in project sonatype-aether by sonatype.

the class DefaultRemoteRepositoryManager method getRepositoryConnector.

public RepositoryConnector getRepositoryConnector(RepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException {
    if (repository == null) {
        throw new IllegalArgumentException("remote repository has not been specified");
    }
    List<RepositoryConnectorFactory> factories = new ArrayList<RepositoryConnectorFactory>(connectorFactories);
    Collections.sort(factories, COMPARATOR);
    for (RepositoryConnectorFactory factory : factories) {
        try {
            RepositoryConnector connector = factory.newInstance(session, repository);
            if (logger.isDebugEnabled()) {
                StringBuilder buffer = new StringBuilder(256);
                buffer.append("Using connector ").append(connector.getClass().getSimpleName());
                buffer.append(" with priority ").append(factory.getPriority());
                buffer.append(" for ").append(repository.getUrl());
                Authentication auth = repository.getAuthentication();
                if (auth != null) {
                    buffer.append(" as ").append(auth.getUsername());
                }
                Proxy proxy = repository.getProxy();
                if (proxy != null) {
                    buffer.append(" via ").append(proxy.getHost()).append(':').append(proxy.getPort());
                    auth = proxy.getAuthentication();
                    if (auth != null) {
                        buffer.append(" as ").append(auth.getUsername());
                    }
                }
                logger.debug(buffer.toString());
            }
            return connector;
        } catch (NoRepositoryConnectorException e) {
        // continue and try next factory
        }
    }
    StringBuilder buffer = new StringBuilder(256);
    buffer.append("No connector available to access repository ");
    buffer.append(repository.getId());
    buffer.append(" (").append(repository.getUrl());
    buffer.append(") of type ").append(repository.getContentType());
    buffer.append(" using the available factories ");
    for (ListIterator<RepositoryConnectorFactory> it = factories.listIterator(); it.hasNext(); ) {
        RepositoryConnectorFactory factory = it.next();
        buffer.append(factory.getClass().getSimpleName());
        if (it.hasNext()) {
            buffer.append(", ");
        }
    }
    throw new NoRepositoryConnectorException(repository, buffer.toString());
}
Also used : Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication) NoRepositoryConnectorException(org.sonatype.aether.transfer.NoRepositoryConnectorException) ArrayList(java.util.ArrayList) RepositoryConnectorFactory(org.sonatype.aether.spi.connector.RepositoryConnectorFactory) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector)

Aggregations

Authentication (org.sonatype.aether.repository.Authentication)20 Proxy (org.sonatype.aether.repository.Proxy)10 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)8 Before (org.junit.Before)6 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 MirrorSelector (org.sonatype.aether.repository.MirrorSelector)2 ProxyServer (com.ning.http.client.ProxyServer)1 Realm (com.ning.http.client.Realm)1 ListIterator (java.util.ListIterator)1 Properties (java.util.Properties)1 RemoteRepository (org.apache.maven.artifact.ant.RemoteRepository)1 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)1 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)1 Repository (org.apache.zeppelin.dep.Repository)1 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)1 Artifact (org.sonatype.aether.artifact.Artifact)1 CollectRequest (org.sonatype.aether.collection.CollectRequest)1 DeployRequest (org.sonatype.aether.deployment.DeployRequest)1 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)1