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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations