org.eclipse.aether.util.repository.AuthenticationBuilder Java Examples

The following examples show how to use org.eclipse.aether.util.repository.AuthenticationBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AetherUtil.java    From buck with Apache License 2.0 6 votes vote down vote up
public static RemoteRepository toRemoteRepository(
    String repoUrl, Optional<String> username, Optional<String> password) {
  RemoteRepository.Builder repo =
      new RemoteRepository.Builder(null, "default", repoUrl)
          .setPolicy(new RepositoryPolicy(true, null, CHECKSUM_POLICY_FAIL));

  if (username.isPresent() && password.isPresent()) {
    Authentication authentication =
        new AuthenticationBuilder()
            .addUsername(username.get())
            .addPassword(password.get())
            .build();
    repo.setAuthentication(authentication);
  }

  return repo.build();
}
 
Example #2
Source File: PublishCommand.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
private org.eclipse.aether.repository.RemoteRepository toRepository(String id,
        RemoteRepository remoteRepository) {
    org.eclipse.aether.repository.RemoteRepository.Builder builder = new org.eclipse.aether.repository.RemoteRepository.Builder(
            id, "default", StringUtils.expandEnvironmentVars(remoteRepository.getUrl()));

    if (remoteRepository.getAuthentication() != null) {
        Authentication auth = remoteRepository.getAuthentication();
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(StringUtils.expandEnvironmentVars(auth.getUsername()))
                .addPassword(StringUtils.expandEnvironmentVars(auth.getPassword())).build())
                .build();
    }

    return builder.build();

}
 
Example #3
Source File: MavenArtifactResolvingHelper.java    From wildfly-swarm with Apache License 2.0 6 votes vote down vote up
protected static RemoteRepository buildRemoteRepository(final String id, final String url,
                                                        final Authentication auth, final Proxy proxy) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (auth != null &&
            auth.getUsername() != null &&
            auth.getPassword() != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                                          .addUsername(auth.getUsername())
                                          .addPassword(auth.getPassword()).build());
    }

    if (proxy != null) {
        builder.setProxy(proxy);
    }

    return builder.build();
}
 
Example #4
Source File: ArtifactRetriever.java    From maven-repository-tools with Eclipse Public License 1.0 6 votes vote down vote up
public void retrieve( List<String> artifactCoordinates, String sourceUrl, String username, 
                     String password, boolean includeSources,
                     boolean includeJavadoc, boolean includeProvidedScope,
                     boolean includeTestScope, boolean includeRuntimeScope )
{
    RemoteRepository.Builder builder = new RemoteRepository.Builder( "central", "default", sourceUrl );
    builder.setProxy( ProxyHelper.getProxy( sourceUrl ) );
    
    Authentication auth = new AuthenticationBuilder()
        .addUsername( username )
        .addPassword( password )
        .build();
    builder.setAuthentication( auth );

    sourceRepository = builder.build();

    getArtifactResults( artifactCoordinates, includeProvidedScope, includeTestScope, includeRuntimeScope );

    getAdditionalArtifactsForRequest( artifactCoordinates );

    getAdditionalArtifactsForArtifactsInCache( includeSources, includeJavadoc );
}
 
Example #5
Source File: MavenTest.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMvn1 () throws Exception
{
    final ChannelTester ct = ChannelTester.create ( getWebContext (), "m1" );
    ct.addAspect ( "mvn" );
    ct.addAspect ( "maven.repo" );
    ct.assignDeployGroup ( "m1" );

    final String key = ct.getDeployKeys ().iterator ().next (); // get first

    assertNotNull ( key );

    final RepositorySystem system = MavenUtil.newRepositorySystem ();
    final RepositorySystemSession session = MavenUtil.newRepositorySystemSession ( system );

    Artifact jarArtifact = new DefaultArtifact ( "org.eclipse.packagedrone.testing", "test.felix1", "", "jar", "0.0.1-SNAPSHOT" );
    jarArtifact = jarArtifact.setFile ( new File ( TEST_1_JAR ) );

    Artifact pomArtifact = new SubArtifact ( jarArtifact, "", "pom" );
    pomArtifact = pomArtifact.setFile ( new File ( TEST_1_POM ) );

    Artifact srcArtifact = new SubArtifact ( jarArtifact, "sources", "jar" );
    srcArtifact = srcArtifact.setFile ( new File ( TEST_1_SOURCES_JAR ) );

    final AuthenticationBuilder ab = new AuthenticationBuilder ();
    ab.addUsername ( "deploy" );
    ab.addPassword ( key );
    final Authentication auth = ab.build ();
    final RemoteRepository distRepo = new RemoteRepository.Builder ( "test", "default", resolve ( String.format ( "/maven/%s", ct.getId () ) ) ).setAuthentication ( auth ).build ();

    final DeployRequest deployRequest = new DeployRequest ();
    deployRequest.addArtifact ( jarArtifact ).addArtifact ( pomArtifact ).addArtifact ( srcArtifact );
    deployRequest.setRepository ( distRepo );

    system.deploy ( session, deployRequest );

    testUrl ( String.format ( "/maven/%s", ct.getId () ) ); // index page

    // FIXME: check more data
}
 
Example #6
Source File: AetherUtil.java    From buck with Apache License 2.0 5 votes vote down vote up
public static RemoteRepository toRemoteRepository(Repository repo) {
  RemoteRepository.Builder builder =
      new RemoteRepository.Builder(repo.getUrl(), "default", repo.getUrl())
          .setPolicy(new RepositoryPolicy(true, null, CHECKSUM_POLICY_FAIL));

  if (repo.user != null && repo.password != null) {
    builder.setAuthentication(
        new AuthenticationBuilder().addUsername(repo.user).addPassword(repo.password).build());
  }

  return builder.build();
}
 
Example #7
Source File: AetherUtils.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
private static Authentication toAuthentication(org.apache.maven.artifact.repository.Authentication auth) {
  Authentication result = null;
  if (auth != null) {
    AuthenticationBuilder authBuilder = new AuthenticationBuilder();
    authBuilder.addUsername(auth.getUsername()).addPassword(auth.getPassword());
    authBuilder.addPrivateKey(auth.getPrivateKey(), auth.getPassphrase());
    result = authBuilder.build();
  }
  return result;
}
 
Example #8
Source File: AetherUtil.java    From vertx-deploy-tools with Apache License 2.0 5 votes vote down vote up
private static RemoteRepository newNexusRepo(DeployConfig deployConfig) {
    if (deployConfig.getNexusUrl() == null) {
        return null;
    }

    RemoteRepository.Builder builder = new RemoteRepository.Builder("nexus", "default", deployConfig.getNexusUrl().toString());
    if (deployConfig.isHttpAuthentication()) {
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(deployConfig.getHttpAuthUser())
                .addPassword(deployConfig.getHttpAuthPassword())
                .build());
    }

    return builder.build();
}
 
Example #9
Source File: RepositoryUtils.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public static org.eclipse.aether.repository.Proxy convertFromMavenProxy(org.apache.maven.settings.Proxy proxy)
{
   org.eclipse.aether.repository.Proxy result = null;
   if (proxy != null)
   {
      Authentication auth = new AuthenticationBuilder().addUsername(proxy.getUsername())
               .addPassword(proxy.getPassword()).build();
      result = new org.eclipse.aether.repository.Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), auth);
   }
   return result;
}
 
Example #10
Source File: MavenRepositories.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
static RemoteRepository convertToMavenRepo(final String id, String url, final Settings settings)
{
   RemoteRepository.Builder remoteRepositoryBuilder = new RemoteRepository.Builder(id, "default", url);
   Proxy activeProxy = settings.getActiveProxy();
   if (activeProxy != null)
   {
      Authentication auth = new AuthenticationBuilder().addUsername(activeProxy.getUsername())
               .addPassword(activeProxy.getPassword()).build();
      remoteRepositoryBuilder.setProxy(new org.eclipse.aether.repository.Proxy(activeProxy.getProtocol(),
               activeProxy
                        .getHost(),
               activeProxy.getPort(), auth));
   }
   return remoteRepositoryBuilder.build();
}
 
Example #11
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private LazyAuthenticationSelector createAuthSelector(final Settings settings,
         final DefaultMirrorSelector mirrorSelector)
{
   LazyAuthenticationSelector authSelector = new LazyAuthenticationSelector(mirrorSelector);
   for (Server server : settings.getServers())
   {
      authSelector.add(
               server.getId(),
               new AuthenticationBuilder().addUsername(server.getUsername()).addPassword(server.getPassword())
                        .addPrivateKey(server.getPrivateKey(), server.getPassphrase()).build());
   }
   return authSelector;
}
 
Example #12
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public static org.eclipse.aether.repository.Proxy convertFromMavenProxy(org.apache.maven.settings.Proxy proxy)
{
   org.eclipse.aether.repository.Proxy result = null;
   if (proxy != null)
   {
      Authentication auth = new AuthenticationBuilder().addUsername(proxy.getUsername())
               .addPassword(proxy.getPassword()).build();
      result = new org.eclipse.aether.repository.Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), auth);
   }
   return result;
}
 
Example #13
Source File: ResolverImpl.java    From vertx-stack with Apache License 2.0 5 votes vote down vote up
private static Authentication extractAuth(URL url) {
  String userInfo = url.getUserInfo();
  if (userInfo != null) {
    AuthenticationBuilder authBuilder = new AuthenticationBuilder();
    int sep = userInfo.indexOf(':');
    if (sep != -1) {
      authBuilder.addUsername(userInfo.substring(0, sep));
      authBuilder.addPassword(userInfo.substring(sep + 1));
    } else {
      authBuilder.addUsername(userInfo);
    }
    return authBuilder.build();
  }
  return null;
}
 
Example #14
Source File: MavenArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
public void remoteRepository(ArtifactRepository repo) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getId(), "default", repo.getUrl());
    final Authentication mavenAuth = repo.getAuthentication();
    if (mavenAuth != null && mavenAuth.getUsername() != null && mavenAuth.getPassword() != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(mavenAuth.getUsername())
                .addPassword(mavenAuth.getPassword()).build());
    }
    this.remoteRepositories.add(builder.build());
}
 
Example #15
Source File: MavenMvnSettings.java    From galleon with Apache License 2.0 5 votes vote down vote up
MavenMvnSettings(MavenConfig config, RepositorySystem repoSystem, RepositoryListener listener) throws ArtifactException {
    this.config = config;
    Settings settings = buildMavenSettings(config.getSettings());
    Proxy proxy = settings.getActiveProxy();
    if (proxy != null) {
        MavenProxySelector.Builder builder = new MavenProxySelector.Builder(proxy.getHost(), proxy.getPort(), proxy.getProtocol());
        builder.setPassword(proxy.getPassword());
        builder.setUserName(proxy.getUsername());
        if (proxy.getNonProxyHosts() != null) {
            String[] hosts = proxy.getNonProxyHosts().split("\\|");
            builder.addNonProxyHosts(Arrays.asList(hosts));
        }
        proxySelector = builder.build();
        Authentication auth = null;
        if (proxy.getPassword() != null && proxy.getUsername() != null) {
            auth = new AuthenticationBuilder().addUsername(proxy.getUsername()).addPassword(proxy.getPassword()).build();
        }
        this.proxy = new org.eclipse.aether.repository.Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), auth);
    } else {
        this.proxy = null;
        proxySelector = null;
    }
    try {
        repositories = Collections.unmodifiableList(buildRemoteRepositories(settings));
    } catch (MalformedURLException ex) {
        throw new ArtifactException(ex.getMessage(), ex);
    }
    session = Util.newRepositorySession(repoSystem,
            settings.getLocalRepository() == null ? config.getLocalRepository() : Paths.get(settings.getLocalRepository()),
            listener, proxySelector, settings.isOffline());
}
 
Example #16
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private ProxySelector createProxySelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultProxySelector selector = new DefaultProxySelector();
	for (Proxy proxy : decryptedSettings.getProxies()) {
		Authentication authentication = new AuthenticationBuilder()
				.addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
				.build();
		selector.add(
				new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
						proxy.getHost(), proxy.getPort(), authentication),
				proxy.getNonProxyHosts());
	}
	return selector;
}
 
Example #17
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private AuthenticationSelector createAuthenticationSelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector();
	for (Server server : decryptedSettings.getServers()) {
		AuthenticationBuilder auth = new AuthenticationBuilder();
		auth.addUsername(server.getUsername()).addPassword(server.getPassword());
		auth.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
		selector.add(server.getId(), auth.build());
	}
	return new ConservativeAuthenticationSelector(selector);
}
 
Example #18
Source File: MavenArtifactResolvingHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private RemoteRepository buildRemoteRepository(final String id, final String url, final Authentication auth,
                                               final ArtifactRepositoryPolicy releasesPolicy, final ArtifactRepositoryPolicy snapshotsPolicy) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (auth != null
            && auth.getUsername() != null
            && auth.getPassword() != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                                          .addUsername(auth.getUsername())
                                          .addPassword(auth.getPassword()).build());
    }

    builder.setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()));
    builder.setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));

    RemoteRepository repository = builder.build();

    final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);

    if (mirror != null) {
        final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector()
                .getAuthentication(mirror);
        RemoteRepository.Builder mirrorBuilder = new RemoteRepository.Builder(mirror)
                .setId(repository.getId())
                .setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()))
                .setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
        if (mirrorAuth != null) {
            mirrorBuilder.setAuthentication(mirrorAuth);
        }
        repository = mirrorBuilder.build();
    }

    Proxy proxy = session.getProxySelector().getProxy(repository);

    if (proxy != null) {
        repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
    }

    return repository;
}
 
Example #19
Source File: MavenInitializer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public static RemoteRepository buildRemoteRepository(final RepositorySystemSession session,
                                                     final String id, final String url, final String username, final String password) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (username != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(username)
                .addPassword(password).build());
    }

    RemoteRepository repository = builder.build();

    final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);

    if (mirror != null) {
        final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector()
                .getAuthentication(mirror);
        RemoteRepository.Builder mirrorBuilder = new RemoteRepository.Builder(mirror)
                .setId(repository.getId());
        if (mirrorAuth != null) {
            mirrorBuilder.setAuthentication(mirrorAuth);
        }
        repository = mirrorBuilder.build();
    }

    Proxy proxy = session.getProxySelector().getProxy(repository);

    if (proxy != null) {
        repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
    }

    return repository;
}
 
Example #20
Source File: AbstractSwarmMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
public static org.eclipse.aether.repository.Proxy convertFromMavenProxy(Proxy proxy) {
    if (proxy != null) {
        return  new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
                                                        proxy.getHost(),
                                                        proxy.getPort(),
                                                        new AuthenticationBuilder()
                                                                .addUsername(proxy.getUsername())
                                                                .addPassword(proxy.getPassword())
                                                                .build());
    }

    return null;
}
 
Example #21
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a {@link org.apache.maven.settings.Proxy} to a {@link Proxy}.
 *
 * @param proxy Maven proxy settings, may be {@code null}.
 * @return Aether repository proxy or {@code null} if given {@link org.apache.maven.settings.Proxy} is {@code null}.
 */
private static Proxy toAetherProxy(org.apache.maven.settings.Proxy proxy) {
    if (proxy == null) {
        return null;
    }
    Authentication auth = null;
    if (proxy.getUsername() != null) {
        auth = new AuthenticationBuilder()
                .addUsername(proxy.getUsername())
                .addPassword(proxy.getPassword())
                .build();
    }
    return new Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), auth);
}
 
Example #22
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private ProxySelector createProxySelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultProxySelector selector = new DefaultProxySelector();
	for (Proxy proxy : decryptedSettings.getProxies()) {
		Authentication authentication = new AuthenticationBuilder()
				.addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
				.build();
		selector.add(
				new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
						proxy.getHost(), proxy.getPort(), authentication),
				proxy.getNonProxyHosts());
	}
	return selector;
}
 
Example #23
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private AuthenticationSelector createAuthenticationSelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector();
	for (Server server : decryptedSettings.getServers()) {
		AuthenticationBuilder auth = new AuthenticationBuilder();
		auth.addUsername(server.getUsername()).addPassword(server.getPassword());
		auth.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
		selector.add(server.getId(), auth.build());
	}
	return new ConservativeAuthenticationSelector(selector);
}
 
Example #24
Source File: AetherStubDownloader.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
Authentication buildAuthentication(String stubServerPassword, String username) {
	return new AuthenticationBuilder().addUsername(username)
			.addPassword(stubServerPassword).build();
}