Search in sources :

Example 1 with HttpRedirectVerifier

use of org.gradle.internal.verifier.HttpRedirectVerifier 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)

Example 2 with HttpRedirectVerifier

use of org.gradle.internal.verifier.HttpRedirectVerifier in project gradle by gradle.

the class DefaultObjectConfigurationAction method applyScript.

private void applyScript(Object script) {
    URI scriptUri = resolver.resolveUri(script);
    TextResource resource;
    if (script instanceof TextResource) {
        resource = (TextResource) script;
    } else {
        HttpRedirectVerifier redirectVerifier = createHttpRedirectVerifier(scriptUri);
        resource = textUriFileResourceLoaderFactory.create(redirectVerifier).loadUri("script", scriptUri);
    }
    ScriptSource scriptSource = new TextResourceScriptSource(resource);
    ClassLoaderScope classLoaderScopeChild = classLoaderScope.createChild("script-" + scriptUri.toString());
    ScriptHandler scriptHandler = scriptHandlerFactory.create(scriptSource, classLoaderScopeChild);
    ScriptPlugin configurer = configurerFactory.create(scriptSource, scriptHandler, classLoaderScopeChild, classLoaderScope, false);
    for (Object target : targets) {
        configurer.apply(target);
    }
}
Also used : TextResource(org.gradle.internal.resource.TextResource) HttpRedirectVerifier(org.gradle.internal.verifier.HttpRedirectVerifier) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ScriptPlugin(org.gradle.configuration.ScriptPlugin) URI(java.net.URI) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) ScriptSource(org.gradle.groovy.scripts.ScriptSource) ScriptHandler(org.gradle.api.initialization.dsl.ScriptHandler)

Example 3 with HttpRedirectVerifier

use of org.gradle.internal.verifier.HttpRedirectVerifier in project gradle by gradle.

the class DefaultTextResourceFactory method fromUri.

private TextResource fromUri(Object uri, boolean allowInsecureProtocol) {
    URI rootUri = fileOperations.uri(uri);
    HttpRedirectVerifier redirectVerifier = HttpRedirectVerifierFactory.create(rootUri, allowInsecureProtocol, () -> throwExceptionDueToInsecureProtocol(rootUri), redirect -> throwExceptionDueToInsecureRedirect(uri, redirect));
    return apiTextResourcesAdapterFactory.create(rootUri, redirectVerifier);
}
Also used : HttpRedirectVerifier(org.gradle.internal.verifier.HttpRedirectVerifier) URI(java.net.URI)

Aggregations

URI (java.net.URI)3 HttpRedirectVerifier (org.gradle.internal.verifier.HttpRedirectVerifier)3 ScriptHandler (org.gradle.api.initialization.dsl.ScriptHandler)1 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)1 Authentication (org.gradle.authentication.Authentication)1 HttpBuildCacheCredentials (org.gradle.caching.http.HttpBuildCacheCredentials)1 ScriptPlugin (org.gradle.configuration.ScriptPlugin)1 ScriptSource (org.gradle.groovy.scripts.ScriptSource)1 TextResourceScriptSource (org.gradle.groovy.scripts.TextResourceScriptSource)1 DefaultBasicAuthentication (org.gradle.internal.authentication.DefaultBasicAuthentication)1 TextResource (org.gradle.internal.resource.TextResource)1 DefaultHttpSettings (org.gradle.internal.resource.transport.http.DefaultHttpSettings)1 HttpClientHelper (org.gradle.internal.resource.transport.http.HttpClientHelper)1