Client not sending proxy credentials

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Client not sending proxy credentials

Al Grant
Hi All,

I am trying to get my https client to get out through our proxy.

I have configured the connection as outlined below but apparently no
credentials are being sent to our proxy so I must be doing something wrong:

        org.apache.cxf.endpoint.Client client =
org.apache.cxf.frontend.ClientProxy.getClient(irsiService);
        org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

        cxfEndpoint.getOutInterceptors().add(loi);
        cxfEndpoint.getInInterceptors().add(lii);

        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.getClient().setProxyServer("webproxy.sales.com.au");
        http.getClient().setProxyServerPort(8080);
        http.getProxyAuthorization().setUserName("username");
        http.getProxyAuthorization().setPassword("password");

        http.setTlsClientParameters(tlsParams);

         // SEND DATA
        response = irsiService.setSale(request);
        System.out.println(response.isSuccess());
        System.out.println("Sent");
        System.out.println("Sale ID: " +response.getSaleId());

Any suggestions?

Cheers

A



--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Andy McCright
Hi Al,

Take a look at what we do in Liberty to configure client proxy
authentication:
https://github.com/OpenLiberty/open-liberty/blob/integration/dev/com.ibm.ws.jaxrs.2.0.client/src/com/ibm/ws/jaxrs20/client/configuration/LibertyJaxRsClientProxyInterceptor.java

The main difference as I see it is that we use the HTTPClientPolicy (that
you get from the HTTPConduit) to set things like the proxy host/port/etc.
and the ProxyAuthorizationPolicy for the username/password.

Hope this helps,

Andy

On Thu, Feb 1, 2018 at 6:00 PM, Al Grant <[hidden email]> wrote:

> Hi All,
>
> I am trying to get my https client to get out through our proxy.
>
> I have configured the connection as outlined below but apparently no
> credentials are being sent to our proxy so I must be doing something wrong:
>
>         org.apache.cxf.endpoint.Client client =
> org.apache.cxf.frontend.ClientProxy.getClient(irsiService);
>         org.apache.cxf.endpoint.Endpoint cxfEndpoint =
> client.getEndpoint();
>
>         cxfEndpoint.getOutInterceptors().add(loi);
>         cxfEndpoint.getInInterceptors().add(lii);
>
>         HTTPConduit http = (HTTPConduit) client.getConduit();
>         http.getClient().setProxyServer("webproxy.sales.com.au");
>         http.getClient().setProxyServerPort(8080);
>         http.getProxyAuthorization().setUserName("username");
>         http.getProxyAuthorization().setPassword("password");
>
>         http.setTlsClientParameters(tlsParams);
>
>          // SEND DATA
>         response = irsiService.setSale(request);
>         System.out.println(response.isSuccess());
>         System.out.println("Sent");
>         System.out.println("Sale ID: " +response.getSaleId());
>
> Any suggestions?
>
> Cheers
>
> A
>
>
>
> --
> Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
>
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Al Grant
Thanks.

So far I can't see how you set a username and password for a Proxy using
that method?



--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Al Grant
In reply to this post by Andy McCright
Or like this? (I can't test it now as I have left the site with proxy):

        org.apache.cxf.endpoint.Client client =
org.apache.cxf.frontend.ClientProxy.getClient(iisrService);
        org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

        cxfEndpoint.getOutInterceptors().add(loi);
        cxfEndpoint.getInInterceptors().add(lii);

        HTTPConduit http = (HTTPConduit) client.getConduit();

        HTTPClientPolicy policy = new HTTPClientPolicy();
        policy.setProxyServer("someproxy.enterprise.au");
        policy.setProxyServerPort(8080);
        http.getProxyAuthorization().setUserName("username");
        http.getProxyAuthorization().setPassword("password");
        http.setClient(policy);

        http.setTlsClientParameters(tlsParams);



--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Al Grant
This post was updated on .
In reply to this post by Andy McCright
Actually just took a second look at your github Andy. More like this perhaps:

        HTTPClientPolicy policy = http.getClient();
        policy.setProxyServer("someproxy.enterprise.au");
        policy.setProxyServerPort(8080);
        http.getProxyAuthorization().setUserName("username");
        http.getProxyAuthorization().setPassword("password");
        http.setClient(policy);

Also is there a way to make this code "smarter" ie use proxy only when needed/detected? Saves me uncommenting it every time I try it out on the other machine.

Cheers

AG




--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Andy McCright
Yes, that looks right.

The username and password should be set on the ProxyAuthorizationPolicy -
you can create a new one, set the user/password, and the pass it to the
HTTPConduit.

Good luck!

Andy

On Thu, Feb 1, 2018 at 10:46 PM Al Grant <[hidden email]> wrote:

> Actually just took a second look at your github Andy. More like this
> perhaps:
>
>         HTTPClientPolicy policy = http.getClient();
>         policy.setProxyServer("someproxy.enterprise.au");
>         policy.setProxyServerPort(8080);
>         http.getProxyAuthorization().setUserName("username");
>         http.getProxyAuthorization().setPassword("password");
>         http.setClient(policy);
>
> Cheers
>
> AG
>
>
>
>
> --
> Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
>
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Al Grant
This post was updated on .
Hmm, its still not sending creds. I am on version 3.1.14

Looking at a few examples online I think I am missing something.

Anyone able to clarify what I am missing? I have tried various variations of using a policy or just

        HTTPConduit http = (HTTPConduit) client.getConduit();

        if (PROXY) {
            HTTPClientPolicy policy = http.getClient();
            policy.setProxyServer("webproxy.test.au");
            policy.setProxyServerPort(8080);
            policy.setReceiveTimeout(600000);
            ProxyAuthorizationPolicy auth = new ProxyAuthorizationPolicy();
            auth.setUserName(pdf.get("username"));
            auth.setPassword(pdf.get("password"));
            //http.getProxyAuthorization().setUserName(pdf.get("username"));
            //http.getProxyAuthorization().setPassword(pdf.get("password"));
            http.setProxyAuthorization(auth);
            http.setClient(policy);
        }

        http.setTlsClientParameters(tlsParams);

        // SEND DATA
        response = isalesService.setSale(request);

I have also tried setting proxy params through:

http.getClient().setProxyServer("webproxy.test.au");


Cheers

AG





--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Al Grant
This post was updated on .
I want to work out which way to set proxy is correct:

METHOD ONE:

https://stackoverflow.com/questions/31550064/apache-cxf-client-proxy-settings

and

https://stackoverflow.com/questions/17214984/ws-client-with-proxy-and-autentification/17216273

Proxy is set with : http.getClient().setProxyServer("proxy");

and then creds and port with

        RSIService rsiService = new RSIService();
        IRSIService irsiService = rsiService.getPort(IRSIService.class)

            http.getClient().setProxyServer("proxy");
            http.getClient().setProxyServerPort(8080);
            http.getClient().setProxyServerType(ProxyServerType.HTTP);
            http.getProxyAuthorization().setUserName(pdf.get("username"));
            http.getProxyAuthorization().setPassword(pdf.get("password"));

I note the example code also has instantiated HelloPortType helloPort =
cliente.getHelloPort(); - I dont have a HelloPortType class for my service
which was generated from WSDL but I do have a rsiService.getPort(IRSIService.class)



METHOD TWO:

https://github.com/apache/cxf/blob/master/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java

They set proxy with pol.setProxyServer("localhost");  - where pol is a HttpClientPolicy.

and then I used :

            ProxyAuthorizationPolicy auth = new ProxyAuthorizationPolicy();
            auth.setUserName(pdf.get("username"));
            auth.setPassword(pdf.get("password"));
            http.setProxyAuthorization(auth);
            http.setClient(policy);

Are both methods valid?

My client seems to contact the correct proxy but never sends creds.

I am on 3.1.14

Thanks

AG





--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

coheigea
Administrator
In reply to this post by Al Grant
On Sun, Feb 11, 2018 at 11:51 PM, Al Grant <[hidden email]> wrote:

>
>             http.setAuthorization(auth);
>

This should be: http.setProxyAuthorization(auth);

Colm.



>             http.setClient(policy);
>         }
>
>         http.setTlsClientParameters(tlsParams);
>
>         // SEND DATA
>         response = isalesService.setSale(request);
>
>
> Cheers
>
> AG
>
>
>
>
>
> --
> Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
>



--
Colm O hEigeartaigh

Talend Community Coder
http://coders.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Client not sending proxy credentials

Al Grant
Thanks - yes it actually goes with this but I have to be very patient.

For some reason it sits there trying to send the message for 10 minutes
before it actually gets to send anything.

It might be something to do with OCSP since i am using mutual TLS - unless
anyone here has other ideas?

Cheers

AG




--
Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html