简体   繁体   中英

Error during https call through proxy using CXF

In camel-cxf I have to call a SOAP webservice (exposed in https) through a proxy: configuring the http conduit as follows

public void configureClient(Client client) {

        String proxySrv = Util.getProperty(Constants.Config.PROXY_SRV);
        int proxyPort = new Integer(Util.getProperty(Constants.Config.PROXY_PORT));
        log.info("Configurazione del server proxy:'"+proxySrv+"' port:'"+proxyPort+"'");
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        HTTPClientPolicy policy = new HTTPClientPolicy();
        policy.setProxyServer(proxySrv); // set proxy host
        policy.setProxyServerPort(proxyPort); // set proxy port
        policy.setProxyServerType(ProxyServerType.SOCKS);
        conduit.setClient(policy);
        conduit.setAuthSupplier(new DefaultBasicAuthSupplier());
        boolean proxyAuthEnabled = new Boolean(Util.getProperty(Constants.Config.PROXY_AUTH_EN));
        String user = Util.getProperty(Constants.Config.PROXY_USER);
        String pass = Util.getProperty(Constants.Config.PROXY_PASS);
        log.info("Recuperati username:'+"+user+"' e password per il proxy:'"+proxySrv+"' port:'"+proxyPort+"'");
        if (proxyAuthEnabled) {
            ProxyAuthorizationPolicy ap =  new ProxyAuthorizationPolicy();
            ap.setUserName(user);
            ap.setPassword(pass);
            conduit.setProxyAuthorization(ap);
//          conduit.getAuthorization().setUserName(user);
//          conduit.getAuthorization().setPassword(pass);
            log.info("Autenticazione abilitata per userName ='"+user+"' per il proxy:'"+proxySrv+"' port:'"+proxyPort+"'");

        }

it works for http call (without the proxy server type set) but it doesn't work for https call. This proxy requires basic auth.

Reading various articles I saw that there is a bug in CXF that doesn't send the header authorization in the CONNECT call (and infact I'm getting 407 Authorization required -> even if with the same credentials with http calls it works).

Is there a way to fix it? I read about Olivier Billard solution

https://www.mail-archive.com/users@cxf.apache.org/msg06422.html

but I didn't undestand that solution (and I can't import at code any keystore).

Thanks

Hello I just faced this issue with the apache cxf client, the workaround suggested in the mailing list is to use the following static method of the java.net.Authenticator class:

Authenticator.setDefault(new Authenticator() {
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("youruser", "yourpassword".toCharArray());
          }
        });

This way the basic will be set automatically on all your HttpUrlConnection that uses the proxy, since java 8 you also have to enable basic authentication for HTTPS tunneling, you can do this with the following property:

-Djdk.http.auth.tunneling.disabledSchemes=""

I hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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