Search in sources :

Example 11 with Authentication

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

the class AuthGetTest method before.

@Before
@Override
public void before() throws Exception {
    super.before();
    repository().setAuthentication(new Authentication("user", "password"));
}
Also used : Authentication(org.sonatype.aether.repository.Authentication) Before(org.junit.Before)

Example 12 with Authentication

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

the class AuthWithNonAsciiCredentialsGetTest method before.

@Before
@Override
public void before() throws Exception {
    super.before();
    repository().setAuthentication(new Authentication("user-non-ascii", "\u00E4\u00DF"));
}
Also used : Authentication(org.sonatype.aether.repository.Authentication) Before(org.junit.Before)

Example 13 with Authentication

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

the class DefaultRepositorySystemSessionTest method testDefaultAuthenticationSelectorUsesExistingAuth.

@Test
public void testDefaultAuthenticationSelectorUsesExistingAuth() {
    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
    RemoteRepository repo = new RemoteRepository("id", "default", "void");
    assertSame(null, session.getAuthenticationSelector().getAuthentication(repo));
    repo.setAuthentication(new Authentication("user", "pass"));
    assertSame(repo.getAuthentication(), session.getAuthenticationSelector().getAuthentication(repo));
}
Also used : Authentication(org.sonatype.aether.repository.Authentication) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 14 with Authentication

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

the class SparkDependencyContext method fetchArtifactWithDep.

private List<ArtifactResult> fetchArtifactWithDep(Dependency dep) throws DependencyResolutionException, ArtifactResolutionException {
    Artifact artifact = new DefaultArtifact(SparkDependencyResolver.inferScalaVersion(dep.getGroupArtifactVersion()));
    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(SparkDependencyResolver.inferScalaVersion(dep.getExclusions()));
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new org.sonatype.aether.graph.Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.addRepository(mavenCentral);
    collectRequest.addRepository(mavenLocal);
    for (RemoteRepository repo : additionalRepos) {
        collectRequest.addRepository(repo);
    }
    for (Repository repo : repositories) {
        RemoteRepository rr = new RemoteRepository(repo.getId(), "default", repo.getUrl());
        rr.setPolicy(repo.isSnapshot(), null);
        Authentication auth = repo.getAuthentication();
        if (auth != null) {
            rr.setAuthentication(auth);
        }
        collectRequest.addRepository(rr);
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFlter));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : Repository(org.apache.zeppelin.dep.Repository) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) Authentication(org.sonatype.aether.repository.Authentication) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)

Example 15 with Authentication

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

the class ArtifactorySonatypeResolversHelper method getResolutionRepositories.

/**
 * Create a list containing one release and one snapshot resolution repositories, according to the configuration in the Artifactory plugin.
 * The list is used to override Maven's default or configured repositories, so that the build dependencies are resolved from Artifactory.
 * The list is saved and reused for further invokations to this method.
 * @param session
 * @return
 */
public List<RemoteRepository> getResolutionRepositories(RepositorySystemSession session) {
    if (resolutionRepositories == null) {
        Properties allMavenProps = new Properties();
        allMavenProps.putAll(session.getSystemProperties());
        allMavenProps.putAll(session.getUserProperties());
        resolutionHelper.init(allMavenProps);
        String releaseRepoUrl = resolutionHelper.getRepoReleaseUrl();
        String snapshotRepoUrl = resolutionHelper.getRepoSnapshotUrl();
        Authentication authentication = null;
        if (StringUtils.isNotBlank(resolutionHelper.getRepoUsername())) {
            authentication = new Authentication(resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword());
        }
        Proxy proxy = null;
        if (StringUtils.isNotBlank(resolutionHelper.getProxyHost())) {
            proxy = new Proxy(null, resolutionHelper.getProxyHost(), resolutionHelper.getProxyPort(), new Authentication(resolutionHelper.getProxyUsername(), resolutionHelper.getProxyPassword()));
        }
        if (StringUtils.isNotBlank(snapshotRepoUrl)) {
            logger.debug("Enforcing snapshot repository for resolution: " + snapshotRepoUrl);
            RepositoryPolicy releasePolicy = new RepositoryPolicy(false, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RepositoryPolicy snapshotPolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            snapshotRepository = new RemoteRepository("artifactory-snapshot", "default", snapshotRepoUrl);
            if (authentication != null) {
                logger.debug("Enforcing repository authentication: " + authentication + " for snapshot resolution repository");
                snapshotRepository.setAuthentication(authentication);
            }
            if (proxy != null) {
                logger.debug("Enforcing proxy: " + proxy + " for snapshot resolution repository");
                snapshotRepository.setProxy(proxy);
            }
            snapshotRepository.setPolicy(false, releasePolicy);
            snapshotRepository.setPolicy(true, snapshotPolicy);
        }
        if (StringUtils.isNotBlank(releaseRepoUrl)) {
            logger.debug("Enforcing release repository for resolution: " + releaseRepoUrl);
            boolean snapshotPolicyEnabled = snapshotRepository == null;
            String repositoryId = snapshotPolicyEnabled ? "artifactory-release-snapshot" : "artifactory-release";
            RepositoryPolicy releasePolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            releaseRepository = new RemoteRepository(repositoryId, "default", releaseRepoUrl);
            if (authentication != null) {
                logger.debug("Enforcing repository authentication: " + authentication + " for release resolution repository");
                releaseRepository.setAuthentication(authentication);
            }
            if (proxy != null) {
                logger.debug("Enforcing proxy: " + proxy + " for release resolution repository");
                releaseRepository.setProxy(proxy);
            }
            releaseRepository.setPolicy(false, releasePolicy);
            releaseRepository.setPolicy(true, snapshotPolicy);
        }
        List<RemoteRepository> tempRepositories = Lists.newArrayList();
        if (releaseRepository != null) {
            tempRepositories.add(releaseRepository);
        }
        if (snapshotRepository != null) {
            tempRepositories.add(snapshotRepository);
        }
        resolutionRepositories = tempRepositories;
    }
    return resolutionRepositories;
}
Also used : Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication) RepositoryPolicy(org.sonatype.aether.repository.RepositoryPolicy) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Properties(java.util.Properties)

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