org.eclipse.aether.repository.Authentication Java Examples

The following examples show how to use org.eclipse.aether.repository.Authentication. 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: AetherStubDownloader.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
private Authentication resolveAuthentication(StubRunnerOptions stubRunnerOptions) {
	if (StringUtils.hasText(stubRunnerOptions.serverId)) {
		Server stubServer = this.settings.getServer(stubRunnerOptions.serverId);
		if (stubServer != null) {
			if (log.isDebugEnabled()) {
				log.debug("Custom server id [" + stubServer.getId()
						+ "] passed will resolve credentials");
			}
			SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(
					stubServer);
			String stubServerPassword = new MavenSettings().createSettingsDecrypter()
					.decrypt(settingsDecryptionRequest).getServer().getPassword();
			return buildAuthentication(stubServerPassword, stubServer.getUsername());
		}
	}
	return buildAuthentication(stubRunnerOptions.password,
			stubRunnerOptions.username);
}
 
Example #3
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 #4
Source File: LazyAuthenticationSelector.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Authentication getAuthentication(RemoteRepository repository)
{
   RemoteRepository mirror = mirrorSelector.getMirror(repository);
   if (mirror != null)
   {
      return defaultAuthSelector.getAuthentication(mirror);
   }
   return defaultAuthSelector.getAuthentication(repository);
}
 
Example #5
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 #6
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 #7
Source File: LazyAuthenticationSelector.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Authentication getAuthentication(RemoteRepository repository)
{
   RemoteRepository mirror = mirrorSelector.getMirror(repository);
   if (mirror != null)
   {
      return defaultAuthSelector.getAuthentication(mirror);
   }
   return defaultAuthSelector.getAuthentication(repository);
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: LazyAuthenticationSelector.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
public void add(String id, Authentication authentication)
{
   defaultAuthSelector.add(id, authentication);
}
 
Example #16
Source File: LazyAuthenticationSelector.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
public void add(String id, Authentication authentication)
{
   defaultAuthSelector.add(id, authentication);
}
 
Example #17
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();
}