You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ianwatson <ia...@redhat.com> on 2016/07/07 14:09:01 UTC

http4 client fails basicAuth whilst http works

Using the following routes it appears the http4 component does not work
specifying the the authUsername/Password. Changing the component to http
solves the issue, it appears therefore that this is a bug with http4. 

A workaround would be to use either the http component of set the
Authorization header manually for example
(setHeader("Authorization").constant("Basic aWFuOmlhbg=="))

The code is below:

from("direct://callRestEndpoint")
                .log(LoggingLevel.DEBUG, ">> Call REST")
                .setHeader("Content-Type").constant("application/json")
                .setHeader("Accept").constant("application/json")
                .setHeader("CamelHttpMethod").constant("POST")
               
.inOut("*http4*://localhost:9191/rest/customerservice/enrich?authUsername=ian&authPassword=ian&authMethod=Basic")





Sample code is below:

Rest service:

restConfiguration().host("localhost").component("jetty").port("9191").endpointProperty("handlers",
"securityHandler");

rest("/rest/customerservice")
           
.post("/enrich").consumes("application/json").produces("application/json").id("rest-customerservice")
            .to("direct://restservice");

Security Handler config in XML:

<bean id="constraint" class="org.eclipse.jetty.util.security.Constraint">
    	<property name="name" value="BASIC"/>
    	<property name="roles" value="ian"/>
    	<property name="authenticate" value="true"/>
	</bean>
 
	<bean id="constraintMapping"
class="org.eclipse.jetty.security.ConstraintMapping">
	    <property name="constraint" ref="constraint"/>
	    <property name="pathSpec" value="/*"/>
	</bean>
	
	<bean id="loginService"
class="org.eclipse.jetty.security.HashLoginService">
		<constructor-arg type="java.lang.String" value="MyRealm"/>
		<constructor-arg type="java.lang.String"
value="src/main/resources/realm.properties"/>
	</bean>
 
	<bean id="securityHandler"
class="org.eclipse.jetty.security.ConstraintSecurityHandler">
	    <property name="authenticator">
	        <bean
class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/>
	    </property>
	    <property name="constraintMappings">
	        <list>
	            <ref bean="constraintMapping"/>
	        </list>
	    </property>
	    <property name="loginService" ref="loginService"></property>
	</bean>




--
View this message in context: http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: http4 client fails basicAuth whilst http works

Posted by ianwatson <ia...@redhat.com>.
User error:

I was specifying the following:

 		from("direct://callRestEndpoint") 
        .log(LoggingLevel.DEBUG, ">> Call REST") 
        .setHeader("Content-Type").constant("application/json") 
        .setHeader("Accept").constant("application/json") 
        .setHeader("CamelHttpMethod").constant("POST") 
        .setHeader("CamelHttpUri")              
        .constant("http4://localhost:9191/rest/customerservice/enrich?authUsername=ian&authPassword=ian&authMethod=Basic")
        .inOut("http4://restclient")

However the header CamelHttpUri does not take into account parameters. These parameters must be specified in the inOut clause. 

i.e

from("direct://callRestEndpoint") 
        .log(LoggingLevel.DEBUG, ">> Call REST") 
        .setHeader("Content-Type").constant("application/json") 
        .setHeader("Accept").constant("application/json") 
        .setHeader("CamelHttpMethod").constant("POST") 
        .setHeader("CamelHttpUri")              
        .constant("http4://localhost:9191/rest/customerservice/enrich")
        .inOut("http4://restclient?authUsername=ian&authPassword=ian&authMethod=Basic")


I’ve marked the post to be deleted.

Thanks
Ian





> On 7 Jul 2016, at 15:42, souciance [via Camel] <ml...@n5.nabble.com> wrote:
> 
>  You mean it didn't work before but now it works and nothing has changed? Seems a bit strange.
> 
> On Thu, Jul 7, 2016 at 4:39 PM, ianwatson [via Camel] <[hidden email] <x-msg://16/user/SendEmail.jtp?type=node&node=5784936&i=0>> wrote:
> Hmm this now seems to be working with/without the preemptive. 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784935.html <http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784935.html>
> To start a new topic under Camel - Users, email [hidden email] <x-msg://16/user/SendEmail.jtp?type=node&node=5784936&i=1> 
> To unsubscribe from Camel - Users, click here <applewebdata://1092E721-E37F-4172-A248-F27F9B190906>.
> NAML <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784936.html <http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784936.html>
> To unsubscribe from http4 client fails basicAuth whilst http works, click here <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5784930&code=aWFud2F0c29uQHJlZGhhdC5jb218NTc4NDkzMHwtMTkxMzM0MTM0Nw==>.
> NAML <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784937.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: http4 client fails basicAuth whilst http works

Posted by souciance <so...@gmail.com>.
 You mean it didn't work before but now it works and nothing has changed?
Seems a bit strange.

On Thu, Jul 7, 2016 at 4:39 PM, ianwatson [via Camel] <
ml-node+s465427n5784935h48@n5.nabble.com> wrote:

> Hmm this now seems to be working with/without the preemptive.
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784935.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784936.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: http4 client fails basicAuth whilst http works

Posted by ianwatson <ia...@redhat.com>.
Hmm this now seems to be working with/without the preemptive.



--
View this message in context: http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784935.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: http4 client fails basicAuth whilst http works

Posted by souciance <so...@gmail.com>.
Just for the sake it, can you add &authenticationPreemptive=true  and try?

On Thu, Jul 7, 2016 at 4:16 PM, ianwatson [via Camel] <
ml-node+s465427n5784933h86@n5.nabble.com> wrote:

> When using authUsername/Password a 401 error
>
> When setting the authorisation header directly the request is authorised.
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784933.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784934.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: http4 client fails basicAuth whilst http works

Posted by ianwatson <ia...@redhat.com>.
When using authUsername/Password a 401 error

When setting the authorisation header directly the request is authorised.



--
View this message in context: http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784933.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: http4 client fails basicAuth whilst http works

Posted by souciance <so...@gmail.com>.
Hi,

What error do you get when you ran it with http4?

Best
Souciance

On Thu, Jul 7, 2016 at 4:09 PM, ianwatson [via Camel] <
ml-node+s465427n5784930h93@n5.nabble.com> wrote:

> Using the following routes it appears the http4 component does not work
> specifying the the authUsername/Password. Changing the component to http
> solves the issue, it appears therefore that this is a bug with http4.
>
> A workaround would be to use either the http component of set the
> Authorization header manually for example
> (setHeader("Authorization").constant("Basic aWFuOmlhbg=="))
>
> The code is below:
>
> from("direct://callRestEndpoint")
>                 .log(LoggingLevel.DEBUG, ">> Call REST")
>                 .setHeader("Content-Type").constant("application/json")
>                 .setHeader("Accept").constant("application/json")
>                 .setHeader("CamelHttpMethod").constant("POST")
>                 .inOut("*http4*://localhost:9191/rest/customerservice/enrich?authUsername=ian&authPassword=ian&authMethod=Basic")
>
>
>
>
>
>
> Sample code is below:
>
> Rest service:
>
> restConfiguration().host("localhost").component("jetty").port("9191").endpointProperty("handlers",
> "securityHandler");
>
> rest("/rest/customerservice")
>
> .post("/enrich").consumes("application/json").produces("application/json").id("rest-customerservice")
>
>             .to("direct://restservice");
>
> Security Handler config in XML:
>
> <bean id="constraint" class="org.eclipse.jetty.util.security.Constraint">
>     <property name="name" value="BASIC"/>
>     <property name="roles" value="ian"/>
>     <property name="authenticate" value="true"/>
>         </bean>
>
>         <bean id="constraintMapping"
> class="org.eclipse.jetty.security.ConstraintMapping">
>             <property name="constraint" ref="constraint"/>
>             <property name="pathSpec" value="/*"/>
>         </bean>
>
>         <bean id="loginService"
> class="org.eclipse.jetty.security.HashLoginService">
>                 <constructor-arg type="java.lang.String" value="MyRealm"/>
>                 <constructor-arg type="java.lang.String"
> value="src/main/resources/realm.properties"/>
>         </bean>
>
>         <bean id="securityHandler"
> class="org.eclipse.jetty.security.ConstraintSecurityHandler">
>             <property name="authenticator">
>                 <bean
> class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/>
>             </property>
>             <property name="constraintMappings">
>                 <list>
>                     <ref bean="constraintMapping"/>
>                 </list>
>             </property>
>             <property name="loginService" ref="loginService"></property>
>         </bean>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/http4-client-fails-basicAuth-whilst-http-works-tp5784930p5784932.html
Sent from the Camel - Users mailing list archive at Nabble.com.