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);
}
}
}
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;
}
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());
}
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;
}
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());
}
Aggregations