Search in sources :

Example 11 with PasswordCredentials

use of org.apache.archiva.repository.PasswordCredentials in project archiva by apache.

the class MavenRepositoryProviderTest method createRemoteInstance.

@Test
public void createRemoteInstance() throws Exception {
    RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
    repo.setUsername("testuser001");
    repo.setPassword("pwd0000abc");
    repo.setCheckPath("test/check.html");
    repo.setTimeout(50);
    repo.setUrl("https://repo.maven.apache.org/maven2/test");
    repo.setDownloadRemoteIndex(true);
    repo.setDownloadRemoteIndexOnStartup(true);
    Map<String, String> header = new HashMap<>();
    header.put("header1", "value1");
    header.put("header2", "value2");
    repo.setExtraHeaders(header);
    Map<String, String> params = new HashMap<>();
    params.put("param1", "pval1");
    params.put("param2", "pval2");
    repo.setExtraParameters(params);
    repo.setRefreshCronExpression("0 1 07 ? * MON");
    repo.setRemoteDownloadTimeout(333);
    repo.setRemoteIndexUrl("testremote/.index");
    repo.setDescription("This is a test");
    repo.setId("test001");
    repo.setName("Remote Test Repo 001");
    repo.setIndexDir("testindex/.index");
    repo.setLayout("maven2");
    repo.setType(RepositoryType.MAVEN.toString());
    repo.setIndexDir("local/.index");
    RemoteRepository mr = provider.createRemoteInstance(repo);
    assertEquals("test001", mr.getId());
    assertEquals("This is a test", mr.getDescription());
    assertNotNull(mr.getLocation());
    assertEquals("https://repo.maven.apache.org/maven2/test", mr.getLocation().toString());
    assertEquals("Remote Test Repo 001", mr.getName());
    assertEquals("test001", mr.getId());
    assertEquals("0 1 07 ? * MON", mr.getSchedulingDefinition());
    assertEquals(50, mr.getTimeout().get(ChronoUnit.SECONDS));
    assertTrue(mr.isScanned());
    assertNotNull(mr.getLoginCredentials());
    assertTrue(mr.getLoginCredentials() instanceof PasswordCredentials);
    PasswordCredentials creds = (PasswordCredentials) mr.getLoginCredentials();
    assertEquals("testuser001", creds.getUsername());
    assertEquals("pwd0000abc", new String(creds.getPassword()));
    assertEquals("value1", mr.getExtraHeaders().get("header1"));
    assertEquals("pval2", mr.getExtraParameters().get("param2"));
    assertEquals("maven2", mr.getLayout());
    try {
        ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature(ArtifactCleanupFeature.class).get();
        throw new Exception("artifactCleanupFeature should not be available");
    } catch (UnsupportedFeatureException e) {
    // correct
    }
    IndexCreationFeature indexCreationFeature = mr.getFeature(IndexCreationFeature.class).get();
    assertEquals("local/.index", indexCreationFeature.getIndexPath().toString());
    try {
        StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature(StagingRepositoryFeature.class).get();
        throw new Exception("stagingRepositoryFeature should not be available");
    } catch (UnsupportedFeatureException e) {
    // correct
    }
    RemoteIndexFeature remoteIndexFeature = mr.getFeature(RemoteIndexFeature.class).get();
    assertNull(remoteIndexFeature.getProxyId());
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedFeatureException(org.apache.archiva.repository.UnsupportedFeatureException) HashMap(java.util.HashMap) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) UnsupportedFeatureException(org.apache.archiva.repository.UnsupportedFeatureException) Test(org.junit.Test)

Example 12 with PasswordCredentials

use of org.apache.archiva.repository.PasswordCredentials in project archiva by apache.

the class MavenRepositoryProvider method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    if (!(remoteRepository instanceof MavenRemoteRepository)) {
        log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
        throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
    }
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    cfg.setType(remoteRepository.getType().toString());
    cfg.setId(remoteRepository.getId());
    cfg.setName(remoteRepository.getName());
    cfg.setDescription(remoteRepository.getDescription());
    cfg.setUrl(remoteRepository.getLocation().toString());
    cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
    cfg.setCheckPath(remoteRepository.getCheckPath());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        if (creds instanceof PasswordCredentials) {
            PasswordCredentials pCreds = (PasswordCredentials) creds;
            cfg.setPassword(new String(pCreds.getPassword()));
            cfg.setUsername(pCreds.getUsername());
        }
    }
    cfg.setLayout(remoteRepository.getLayout());
    cfg.setExtraParameters(remoteRepository.getExtraParameters());
    cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
    cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
    cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
    cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
    cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
    cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
    cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
    return cfg;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 13 with PasswordCredentials

use of org.apache.archiva.repository.PasswordCredentials in project archiva by apache.

the class MavenRepositoryProvider method updateRemoteInstance.

@Override
public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
    setBaseConfig(repo, cfg);
    repo.setCheckPath(cfg.getCheckPath());
    repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
    try {
        repo.setLocation(new URI(cfg.getUrl()));
    } catch (UnsupportedURIException | URISyntaxException e) {
        log.error("Could not set remote url " + cfg.getUrl());
        throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
    }
    repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
    RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
    remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
    remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
    remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
    remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
    if (cfg.isDownloadRemoteIndex()) {
        try {
            remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
        } catch (URISyntaxException e) {
            log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
            remoteIndexFeature.setDownloadRemoteIndex(false);
            remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
        }
    }
    for (Object key : cfg.getExtraHeaders().keySet()) {
        repo.addExtraHeader(key.toString(), cfg.getExtraHeaders().get(key).toString());
    }
    for (Object key : cfg.getExtraParameters().keySet()) {
        repo.addExtraParameter(key.toString(), cfg.getExtraParameters().get(key).toString());
    }
    PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
    if (cfg.getPassword() != null && cfg.getUsername() != null) {
        credentials.setPassword(cfg.getPassword().toCharArray());
        credentials.setUsername(cfg.getUsername());
        repo.setCredentials(credentials);
    } else {
        credentials.setPassword(new char[0]);
    }
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    if (cfg.getIndexDir() != null) {
        indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
    }
    if (cfg.getPackedIndexDir() != null) {
        indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
    }
    log.debug("Updated remote instance {}", repo);
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedURIException(org.apache.archiva.repository.UnsupportedURIException) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)13 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)7 URI (java.net.URI)6 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)5 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)4 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)4 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)4 IndexUpdateRequest (org.apache.maven.index.updater.IndexUpdateRequest)4 ResourceFetcher (org.apache.maven.index.updater.ResourceFetcher)4 ConnectionException (org.apache.maven.wagon.ConnectionException)4 StreamWagon (org.apache.maven.wagon.StreamWagon)4 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)4 AbstractHttpClientWagon (org.apache.maven.wagon.shared.http.AbstractHttpClientWagon)4 HttpConfiguration (org.apache.maven.wagon.shared.http.HttpConfiguration)4