简体   繁体   English

骆驼Http4使用基本身份验证和代理身份验证

[英]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. 我一直在尝试使用Apache Camel的Http4组件连接到需要基本身份验证的HTTPS URL。 The connection needs to be done through an authenticated HTTP proxy. 连接需要通过经过身份验证的HTTP代理完成。

So, according to the docs , I configure the Camel endpoint like this: 因此,根据docs ,我将Camel端点配置为:

.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. 这将导致目标服务器发出403 - Forbidden响应。 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. 通过寻找org.apache.http.wire日志,它示出了代理证书PROXYUSER / 的proxyPassword被转发到在所述目标服务器,而不是预期的MYUSER / MYPASSWORD Authorization报头。

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. 调试CompositeHTTPConfigurer.configureHttpClientProxyHttpClientConfigurer.configureHttpClientBasicAuthenticationHttpClientConfigurer.configureHttpClient的源时,似乎由于两个配置程序都通过setDefaultCredentialsProvider将其凭据设置为HttpClientBuilder ,因此其中一个丢失-在过程中被覆盖。

Looks like it could be a bug in Camel's Http4 component? 看起来可能是骆驼的Http4组件中的错误? Or am I missing something? 还是我错过了什么?

This is Camel 2.18.2 with Spring Boot 1.5.1.RELEASE. 这是带有Spring Boot 1.5.1.RELEASE的Camel 2.18.2。

After raising this question on the Apache Camel Users list , it seems the bug is confirmed. Apache Camel用户列表中提出此问题后,似乎该错误已得到确认。

I solved it using camel-http instead of camel-http4 . 我使用camel-http而不是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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM