Search in sources :

Example 1 with HttpBuildCacheCredentials

use of org.gradle.caching.http.HttpBuildCacheCredentials in project gradle by gradle.

the class DefaultHttpBuildCacheServiceFactory method extractCredentialsFromUserInfo.

@VisibleForTesting
static HttpBuildCacheCredentials extractCredentialsFromUserInfo(URI url) {
    HttpBuildCacheCredentials credentials = new HttpBuildCacheCredentials();
    String userInfo = url.getUserInfo();
    int indexOfSeparator = userInfo.indexOf(':');
    if (indexOfSeparator > -1) {
        String username = userInfo.substring(0, indexOfSeparator);
        String password = userInfo.substring(indexOfSeparator + 1);
        credentials.setUsername(username);
        credentials.setPassword(password);
    }
    return credentials;
}
Also used : HttpBuildCacheCredentials(org.gradle.caching.http.HttpBuildCacheCredentials) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with HttpBuildCacheCredentials

use of org.gradle.caching.http.HttpBuildCacheCredentials in project gradle by gradle.

the class DefaultHttpBuildCacheServiceFactory method createBuildCacheService.

@Override
public BuildCacheService createBuildCacheService(HttpBuildCache configuration, Describer describer) {
    URI url = configuration.getUrl();
    if (url == null) {
        throw new IllegalStateException("HTTP build cache has no URL configured");
    }
    URI noUserInfoUrl = stripUserInfo(url);
    HttpBuildCacheCredentials credentials = configuration.getCredentials();
    if (!credentialsPresent(credentials) && url.getUserInfo() != null) {
        credentials = extractCredentialsFromUserInfo(url);
    }
    Collection<Authentication> authentications = Collections.emptyList();
    if (credentialsPresent(credentials)) {
        DefaultBasicAuthentication basicAuthentication = new DefaultBasicAuthentication("basic");
        basicAuthentication.setCredentials(credentials);
        basicAuthentication.addHost(url.getHost(), url.getPort());
        authentications = Collections.<Authentication>singleton(basicAuthentication);
    }
    boolean authenticated = !authentications.isEmpty();
    boolean allowUntrustedServer = configuration.isAllowUntrustedServer();
    boolean allowInsecureProtocol = configuration.isAllowInsecureProtocol();
    boolean useExpectContinue = configuration.isUseExpectContinue();
    HttpRedirectVerifier redirectVerifier = createRedirectVerifier(noUserInfoUrl, allowInsecureProtocol);
    DefaultHttpSettings.Builder builder = DefaultHttpSettings.builder().withAuthenticationSettings(authentications).maxRedirects(MAX_REDIRECTS).withRedirectMethodHandlingStrategy(HttpSettings.RedirectMethodHandlingStrategy.ALLOW_FOLLOW_FOR_MUTATIONS).withRedirectVerifier(redirectVerifier);
    if (allowUntrustedServer) {
        builder.allowUntrustedConnections();
    } else {
        builder.withSslContextFactory(sslContextFactory);
    }
    HttpClientHelper httpClientHelper = httpClientHelperFactory.create(builder.build());
    describer.type("HTTP").config("url", noUserInfoUrl.toASCIIString()).config("authenticated", Boolean.toString(authenticated)).config("allowUntrustedServer", Boolean.toString(allowUntrustedServer)).config("allowInsecureProtocol", Boolean.toString(allowInsecureProtocol)).config("useExpectContinue", Boolean.toString(useExpectContinue));
    return new HttpBuildCacheService(httpClientHelper, noUserInfoUrl, requestCustomizer, useExpectContinue);
}
Also used : HttpClientHelper(org.gradle.internal.resource.transport.http.HttpClientHelper) HttpRedirectVerifier(org.gradle.internal.verifier.HttpRedirectVerifier) Authentication(org.gradle.authentication.Authentication) DefaultBasicAuthentication(org.gradle.internal.authentication.DefaultBasicAuthentication) DefaultBasicAuthentication(org.gradle.internal.authentication.DefaultBasicAuthentication) DefaultHttpSettings(org.gradle.internal.resource.transport.http.DefaultHttpSettings) HttpBuildCacheCredentials(org.gradle.caching.http.HttpBuildCacheCredentials) URI(java.net.URI)

Aggregations

HttpBuildCacheCredentials (org.gradle.caching.http.HttpBuildCacheCredentials)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 URI (java.net.URI)1 Authentication (org.gradle.authentication.Authentication)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 HttpRedirectVerifier (org.gradle.internal.verifier.HttpRedirectVerifier)1