javaapache-camelproxy-authenticationcamel-http

Camel Http4 using basic auth and proxy auth


I've been trying to use Apache Camel's Http4 component to connect to a HTTPS URL that needs Basic authentication. The connection needs to be done through an authenticated HTTP proxy.

So, according to the docs, I configure the Camel endpoint like this:

.toD("https4://target.host/resource?
        bridgeEndpoint=true
        &mapHttpMessageBody=false

        &proxyAuthHost=my.proxy.host
        &proxyAuthPort=myProxyPort
        &proxyAuthUsername=proxyUser
        &proxyAuthPassword=proxyPassword
        &proxyAuthScheme=http4

        &authenticationPreemptive=true
        &authUsername=myUser
        &authPassword=myPassword")

Which results in a 403 - Forbidden response from the target server. Looking through the org.apache.http.wire logs, it shows that the proxy credentials proxyUser / proxyPassword are forwarded to the target server instead of the intended myUser/myPassword in the Authorization header.

Debugging the source for CompositeHTTPConfigurer.configureHttpClient, ProxyHttpClientConfigurer.configureHttpClient and BasicAuthenticationHttpClientConfigurer.configureHttpClient, it seems that because both configurers are setting their credentials to the HttpClientBuilder by means of setDefaultCredentialsProvider, one of them is lost - gets overwritten - in the process.

Looks like it could be a bug in Camel's Http4 component? Or am I missing something?

This is Camel 2.18.2 with Spring Boot 1.5.1.RELEASE.


Solution

  • After raising this question on the Apache Camel Users list, it seems the bug is confirmed.

    I solved it using camel-http instead of camel-http4. Endpoint parameters needed a slight tweaking:

    .toD("https://target.host/resource?
        bridgeEndpoint=true
    
        &proxyHost=my.proxy.host
        &proxyPort=myProxyPort
        &proxyAuthUsername=proxyUser
        &proxyAuthPassword=proxyPassword
        &proxyAuthMethod=Basic
    
        &authUsername=myUser
        &authPassword=myPassword
        &authMethod=Basic
        &httpClient.authenticationPreemptive=true")