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