Search in sources :

Example 6 with PasswordCredentials

use of org.apache.archiva.repository.base.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);
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class);
    if (remoteIndexFeature.getIndexUri() == null) {
        cfg.setRemoteIndexUrl("");
    } else {
        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());
    if (StringUtils.isEmpty(remoteIndexFeature.getProxyId())) {
        cfg.setRemoteDownloadNetworkProxyId("");
    } else {
        cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
    }
    return cfg;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 7 with PasswordCredentials

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

the class RepositoryProviderMock method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(remoteRepository.getId());
    configuration.setName(remoteRepository.getName());
    configuration.setDescription(remoteRepository.getDescription());
    configuration.setLayout(remoteRepository.getLayout());
    configuration.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    configuration.setCheckPath(remoteRepository.getCheckPath());
    configuration.setExtraHeaders(remoteRepository.getExtraHeaders());
    configuration.setExtraParameters(remoteRepository.getExtraParameters());
    configuration.setTimeout((int) remoteRepository.getTimeout().getSeconds());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        PasswordCredentials pwdCreds = (PasswordCredentials) creds;
        configuration.setUsername(pwdCreds.getUsername());
        configuration.setPassword(new String(pwdCreds.getPassword()));
    }
    configuration.setUrl(remoteRepository.getLocation() == null ? "" : remoteRepository.getLocation().toString());
    RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
    configuration.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
    configuration.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
    configuration.setIndexDir(rif.getIndexUri() == null ? "" : rif.getIndexUri().toString());
    configuration.setRemoteDownloadNetworkProxyId(rif.getProxyId());
    return configuration;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Example 8 with PasswordCredentials

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

the class RepositoryProviderMock method updateRemoteInstance.

@Override
public void updateRemoteInstance(EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration) throws RepositoryException {
    try {
        remoteRepository.setName(remoteRepository.getPrimaryLocale(), configuration.getName());
        remoteRepository.setBaseUri(new URI(""));
        remoteRepository.setDescription(remoteRepository.getPrimaryLocale(), configuration.getDescription());
        remoteRepository.setLayout(configuration.getLayout());
        remoteRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        remoteRepository.setCheckPath(configuration.getCheckPath());
        remoteRepository.setExtraHeaders(configuration.getExtraHeaders());
        remoteRepository.setExtraParameters(configuration.getExtraParameters());
        remoteRepository.setTimeout(Duration.ofSeconds(configuration.getTimeout()));
        char[] pwd = configuration.getPassword() == null ? "".toCharArray() : configuration.getPassword().toCharArray();
        remoteRepository.setCredentials(new PasswordCredentials(configuration.getUsername(), pwd));
        remoteRepository.setLocation(new URI(configuration.getUrl() == null ? "" : configuration.getUrl()));
        RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
        rif.setDownloadRemoteIndexOnStartup(configuration.isDownloadRemoteIndexOnStartup());
        rif.setDownloadRemoteIndex(configuration.isDownloadRemoteIndex());
        rif.setIndexUri(new URI(configuration.getIndexDir()));
        rif.setDownloadTimeout(Duration.ofSeconds(configuration.getRemoteDownloadTimeout()));
        rif.setProxyId(configuration.getRemoteDownloadNetworkProxyId());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException)

Example 9 with PasswordCredentials

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

the class RepositoryProviderMock method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) {
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(remoteRepository.getId());
    configuration.setName(remoteRepository.getName());
    configuration.setDescription(remoteRepository.getDescription());
    configuration.setLayout(remoteRepository.getLayout());
    configuration.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    configuration.setCheckPath(remoteRepository.getCheckPath());
    configuration.setExtraHeaders(remoteRepository.getExtraHeaders());
    configuration.setExtraParameters(remoteRepository.getExtraParameters());
    configuration.setTimeout((int) remoteRepository.getTimeout().getSeconds());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        PasswordCredentials pwdCreds = (PasswordCredentials) creds;
        configuration.setUsername(pwdCreds.getUsername());
        configuration.setPassword(new String(pwdCreds.getPassword()));
    }
    configuration.setUrl(remoteRepository.getLocation() == null ? "" : remoteRepository.getLocation().toString());
    RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
    configuration.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
    configuration.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
    configuration.setIndexDir(rif.getIndexUri() == null ? "" : rif.getIndexUri().toString());
    configuration.setRemoteDownloadNetworkProxyId(rif.getProxyId());
    return configuration;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Example 10 with PasswordCredentials

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

the class RepositoryProviderMock method updateRemoteInstance.

@SuppressWarnings("unchecked")
@Override
public void updateRemoteInstance(EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration) throws RepositoryException {
    try {
        remoteRepository.setName(remoteRepository.getPrimaryLocale(), configuration.getName());
        remoteRepository.setBaseUri(new URI(""));
        remoteRepository.setDescription(remoteRepository.getPrimaryLocale(), configuration.getDescription());
        remoteRepository.setLayout(configuration.getLayout());
        remoteRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        remoteRepository.setCheckPath(configuration.getCheckPath());
        remoteRepository.setExtraHeaders(configuration.getExtraHeaders());
        remoteRepository.setExtraParameters(configuration.getExtraParameters());
        remoteRepository.setTimeout(Duration.ofSeconds(configuration.getTimeout()));
        char[] pwd = configuration.getPassword() == null ? "".toCharArray() : configuration.getPassword().toCharArray();
        remoteRepository.setCredentials(new PasswordCredentials(configuration.getUsername(), pwd));
        remoteRepository.setLocation(new URI(configuration.getUrl() == null ? "" : configuration.getUrl()));
        RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
        rif.setDownloadRemoteIndexOnStartup(configuration.isDownloadRemoteIndexOnStartup());
        rif.setDownloadRemoteIndex(configuration.isDownloadRemoteIndex());
        rif.setIndexUri(new URI(configuration.getIndexDir()));
        rif.setDownloadTimeout(Duration.ofSeconds(configuration.getRemoteDownloadTimeout()));
        rif.setProxyId(configuration.getRemoteDownloadNetworkProxyId());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException)

Aggregations

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