Search in sources :

Example 1 with Authentication

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);
    }
}
Also used : PasswordCredentials(org.gradle.api.credentials.PasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTLMCredentials(org.gradle.internal.resource.transport.http.ntlm.NTLMCredentials) Authentication(org.gradle.authentication.Authentication) DigestAuthentication(org.gradle.authentication.http.DigestAuthentication) AllSchemesAuthentication(org.gradle.internal.authentication.AllSchemesAuthentication) BasicAuthentication(org.gradle.authentication.http.BasicAuthentication) AuthScope(org.apache.http.auth.AuthScope) AllSchemesAuthentication(org.gradle.internal.authentication.AllSchemesAuthentication) PasswordCredentials(org.gradle.api.credentials.PasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(org.apache.http.auth.Credentials) NTLMCredentials(org.gradle.internal.resource.transport.http.ntlm.NTLMCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with Authentication

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));
        }
    }
}
Also used : Authentication(org.gradle.authentication.Authentication) InvalidUserDataException(org.gradle.api.InvalidUserDataException) AuthenticationInternal(org.gradle.internal.authentication.AuthenticationInternal) Credentials(org.gradle.api.credentials.Credentials)

Example 3 with 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);
}
Also used : HttpClientHelper(org.gradle.internal.resource.transport.http.HttpClientHelper) Authentication(org.gradle.authentication.Authentication) DefaultBasicAuthentication(org.gradle.internal.authentication.DefaultBasicAuthentication) GradleException(org.gradle.api.GradleException) DefaultBasicAuthentication(org.gradle.internal.authentication.DefaultBasicAuthentication) URISyntaxException(java.net.URISyntaxException) DefaultHttpSettings(org.gradle.internal.resource.transport.http.DefaultHttpSettings) URI(java.net.URI)

Example 4 with Authentication

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;
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) Authentication(org.gradle.authentication.Authentication) IvyResolver(org.gradle.api.internal.artifacts.repositories.resolver.IvyResolver) File(java.io.File)

Aggregations

Authentication (org.gradle.authentication.Authentication)4 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 NTCredentials (org.apache.http.auth.NTCredentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 GradleException (org.gradle.api.GradleException)1 Credentials (org.gradle.api.credentials.Credentials)1 PasswordCredentials (org.gradle.api.credentials.PasswordCredentials)1 IvyResolver (org.gradle.api.internal.artifacts.repositories.resolver.IvyResolver)1 BasicAuthentication (org.gradle.authentication.http.BasicAuthentication)1 DigestAuthentication (org.gradle.authentication.http.DigestAuthentication)1 AllSchemesAuthentication (org.gradle.internal.authentication.AllSchemesAuthentication)1 AuthenticationInternal (org.gradle.internal.authentication.AuthenticationInternal)1 DefaultBasicAuthentication (org.gradle.internal.authentication.DefaultBasicAuthentication)1 DefaultHttpSettings (org.gradle.internal.resource.transport.http.DefaultHttpSettings)1 HttpClientHelper (org.gradle.internal.resource.transport.http.HttpClientHelper)1