use of org.gradle.authentication.Authentication in project gradle by gradle.
the class HttpClientConfigurer method useCredentials.
private void useCredentials(CredentialsProvider credentialsProvider, String host, int port, Collection<? extends Authentication> authentications) {
Credentials httpCredentials;
for (Authentication authentication : authentications) {
String scheme = getAuthScheme(authentication);
PasswordCredentials credentials = getPasswordCredentials(authentication);
if (authentication instanceof AllSchemesAuthentication) {
NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
httpCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthSchemes.NTLM), httpCredentials);
LOGGER.debug("Using {} and {} for authenticating against '{}:{}' using {}", credentials, ntlmCredentials, host, port, AuthSchemes.NTLM);
}
httpCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, scheme), httpCredentials);
LOGGER.debug("Using {} for authenticating against '{}:{}' using {}", credentials, host, port, scheme);
}
}
use of org.gradle.authentication.Authentication in project gradle by gradle.
the class RepositoryTransportFactory method validateConnectorFactoryCredentials.
private void validateConnectorFactoryCredentials(Set<String> schemes, ResourceConnectorFactory factory, Collection<Authentication> authentications) {
Set<Class<? extends Authentication>> configuredAuthenticationTypes = Sets.newHashSet();
for (Authentication authentication : authentications) {
AuthenticationInternal authenticationInternal = (AuthenticationInternal) authentication;
boolean isAuthenticationSupported = false;
Credentials credentials = authenticationInternal.getCredentials();
boolean needCredentials = authenticationInternal.requiresCredentials();
for (Class<?> authenticationType : factory.getSupportedAuthentication()) {
if (authenticationType.isAssignableFrom(authentication.getClass())) {
isAuthenticationSupported = true;
break;
}
}
if (!isAuthenticationSupported) {
throw new InvalidUserDataException(String.format("Authentication scheme %s is not supported by protocol '%s'", authentication, schemes.iterator().next()));
}
if (credentials != null) {
if (!((AuthenticationInternal) authentication).supports(credentials)) {
throw new InvalidUserDataException(String.format("Credentials type of '%s' is not supported by authentication scheme %s", credentials.getClass().getSimpleName(), authentication));
}
} else {
if (needCredentials) {
throw new InvalidUserDataException("You cannot configure authentication schemes for this repository type if no credentials are provided.");
}
}
if (!configuredAuthenticationTypes.add(authenticationInternal.getType())) {
throw new InvalidUserDataException(String.format("You cannot configure multiple authentication schemes of the same type. The duplicate one is %s.", authentication));
}
}
}
use of org.gradle.authentication.Authentication in project gradle by gradle.
the class DefaultHttpBuildCacheServiceFactory method createBuildCacheService.
@Override
public BuildCacheService createBuildCacheService(HttpBuildCache configuration) {
URI url = configuration.getUrl();
if (url == null) {
throw new IllegalStateException("HTTP build cache has no URL configured");
}
Collection<Authentication> authentications = Collections.emptyList();
if (configuration.getCredentials().getUsername() != null && configuration.getCredentials().getPassword() != null) {
try {
url = new URI(url.getScheme(), null, url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getFragment());
} catch (URISyntaxException e) {
throw new GradleException("Error constructing URL for http build cache", e);
}
DefaultBasicAuthentication basicAuthentication = new DefaultBasicAuthentication("basic");
basicAuthentication.setCredentials(configuration.getCredentials());
authentications = Collections.<Authentication>singleton(basicAuthentication);
}
HttpClientHelper httpClientHelper = new HttpClientHelper(new DefaultHttpSettings(authentications, sslContextFactory));
return new HttpBuildCacheService(httpClientHelper, url);
}
use of org.gradle.authentication.Authentication in project gradle by gradle.
the class DefaultFlatDirArtifactRepository method createRealResolver.
private IvyResolver createRealResolver() {
Set<File> dirs = getDirs();
if (dirs.isEmpty()) {
throw new InvalidUserDataException("You must specify at least one directory for a flat directory repository.");
}
IvyResolver resolver = new IvyResolver(getName(), transportFactory.createTransport("file", getName(), Collections.<Authentication>emptyList()), locallyAvailableResourceFinder, false, artifactFileStore, ivyContextManager, moduleIdentifierFactory, null);
for (File root : dirs) {
resolver.addArtifactLocation(root.toURI(), "/[artifact]-[revision](-[classifier]).[ext]");
resolver.addArtifactLocation(root.toURI(), "/[artifact](-[classifier]).[ext]");
}
return resolver;
}
Aggregations