You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Gerald Kallas <ca...@mailbox.org> on 2020/02/03 17:34:11 UTC

REST API - Basic Authentication?

Dear community,

I've following REST API (see below).

How can I add a Basic Authentication to the REST API in Blueprint DSL? Any hints are highly welcome.

Best
- Gerald

Configuration XML ..

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

	<reference id="httpService" interface="org.osgi.service.http.HttpService"/>

	<bean id="camelHttpTransportServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>

	<bean id="servlet" class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
        init-method="register"
        destroy-method="unregister">
		<property name="alias" value="/api"/>
		<property name="httpService" ref="httpService"/>
		<property name="servlet" ref="camelHttpTransportServlet"/>
	</bean>

</blueprint>

.. and REST API ..

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

	<camelContext id="isp.routes.RST" xmlns="http://camel.apache.org/schema/blueprint" streamCache="true">

		<restConfiguration component="servlet" bindingMode="json" contextPath="/api" port="443">
			<dataFormatProperty key="prettyPrint" value="true"/>
		</restConfiguration>

		<rest path="/say">
			<get uri="/hello" consumes="application/json" id="isp.routes.RST001">
				<to uri="direct:hello"/>
			</get>
			<get uri="/bye" consumes="application/json" id="isp.routes.RST002">
				<to uri="direct:bye"/>
			</get>
		</rest>

		<route id="isp.routes.RST003">
			<from uri="direct:hello"/>
			<setHeader name="Content-Type">
				<constant>application/json</constant>
			</setHeader>
			<transform>
				<constant>{"text": "Hello World"}</constant>
			</transform>
		</route>

		<route id="isp.routes.RST004">
			<from uri="direct:bye"/>
			<setHeader name="Content-Type">
				<constant>application/json</constant>
			</setHeader>
			<transform>
				<constant>{"text": "Bye World"}</constant>
			</transform>
		</route>

	</camelContext>

</blueprint>

Re: REST API - Basic Authentication?

Posted by Alex Soto <al...@envieta.com>.
I found a solution.  See here:


http://karaf.922171.n3.nabble.com/Basic-authentication-of-WAB-using-Jaas-in-Karaf-tp4058251p4058280.html <http://karaf.922171.n3.nabble.com/Basic-authentication-of-WAB-using-Jaas-in-Karaf-tp4058251p4058280.html>



Best regards,
Alex soto




> On May 13, 2020, at 12:57 PM, Jeremy Ross <je...@gmail.com> wrote:
> 
> I discovered that exchange headers are used for HTTP headers. Setting a
> header called `Authorization` on the exchange to `Basic <base64encode(un +
> ":" + pw)>` worked for me.
> 
> On Tue, May 12, 2020 at 11:55 AM Alex Soto <al...@envieta.com> wrote:
> 
>> Hello,
>> 
>> I am facing the same issue,  using Camel Rest DSL on top of Servlet,
>> Blueprint, Karaf, Pax-Web, Jetty, how to add Basic authentication to the
>> Rest endpoints?   Any pointers/examples will be appreciated.
>> 
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
>> 
>>> On Feb 4, 2020, at 3:15 AM, Gerald Kallas - mailbox.org <
>> catshout@mailbox.org> wrote:
>>> 
>>> Tx JB.
>>> 
>>> At the moment I decided to register a servlet to re-use the global Jetty
>> configuration.
>>> 
>>> So where I can find the filter stuff?
>>> 
>>> For best practices ..
>>> 
>>> 1. better to use servlet or camel-jetty?
>>> 2. one servlet for multiple APIs or one dedicated servlet for every API?
>>> 
>>> Best
>>> - Gerald
>>> 
>>>> Am 04.02.2020 um 05:56 schrieb Jean-Baptiste Onofré <jb...@nanthrax.net>:
>>>> 
>>>> Hi,
>>>> 
>>>> Not sure I follow (related to your previous message): are you using
>>>> servlet registration or camel-jetty ?
>>>> 
>>>> On camel-jetty, you can define a security handler.
>>>> 
>>>> Using servlet, you can always register a filter.
>>>> 
>>>> Regards
>>>> JB
>>>> 
>>>>> On 03/02/2020 18:34, Gerald Kallas wrote:
>>>>> Dear community,
>>>>> 
>>>>> I've following REST API (see below).
>>>>> 
>>>>> How can I add a Basic Authentication to the REST API in Blueprint DSL?
>> Any hints are highly welcome.
>>>>> 
>>>>> Best
>>>>> - Gerald
>>>>> 
>>>>> Configuration XML ..
>>>>> 
>>>>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>>>> 
>>>>>  <reference id="httpService"
>> interface="org.osgi.service.http.HttpService"/>
>>>>> 
>>>>>  <bean id="camelHttpTransportServlet"
>> class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
>>>>> 
>>>>>  <bean id="servlet"
>> class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
>>>>>      init-method="register"
>>>>>      destroy-method="unregister">
>>>>>      <property name="alias" value="/api"/>
>>>>>      <property name="httpService" ref="httpService"/>
>>>>>      <property name="servlet" ref="camelHttpTransportServlet"/>
>>>>>  </bean>
>>>>> 
>>>>> </blueprint>
>>>>> 
>>>>> .. and REST API ..
>>>>> 
>>>>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>>>> 
>>>>>  <camelContext id="isp.routes.RST" xmlns="
>> http://camel.apache.org/schema/blueprint" streamCache="true">
>>>>> 
>>>>>      <restConfiguration component="servlet" bindingMode="json"
>> contextPath="/api" port="443">
>>>>>          <dataFormatProperty key="prettyPrint" value="true"/>
>>>>>      </restConfiguration>
>>>>> 
>>>>>      <rest path="/say">
>>>>>          <get uri="/hello" consumes="application/json"
>> id="isp.routes.RST001">
>>>>>              <to uri="direct:hello"/>
>>>>>          </get>
>>>>>          <get uri="/bye" consumes="application/json"
>> id="isp.routes.RST002">
>>>>>              <to uri="direct:bye"/>
>>>>>          </get>
>>>>>      </rest>
>>>>> 
>>>>>      <route id="isp.routes.RST003">
>>>>>          <from uri="direct:hello"/>
>>>>>          <setHeader name="Content-Type">
>>>>>              <constant>application/json</constant>
>>>>>          </setHeader>
>>>>>          <transform>
>>>>>              <constant>{"text": "Hello World"}</constant>
>>>>>          </transform>
>>>>>      </route>
>>>>> 
>>>>>      <route id="isp.routes.RST004">
>>>>>          <from uri="direct:bye"/>
>>>>>          <setHeader name="Content-Type">
>>>>>              <constant>application/json</constant>
>>>>>          </setHeader>
>>>>>          <transform>
>>>>>              <constant>{"text": "Bye World"}</constant>
>>>>>          </transform>
>>>>>      </route>
>>>>> 
>>>>>  </camelContext>
>>>>> 
>>>>> </blueprint>
>>>>> 
>>>> 
>>>> --
>>>> Jean-Baptiste Onofré
>>>> jbonofre@apache.org
>>>> http://blog.nanthrax.net
>>>> Talend - http://www.talend.com
>>> 
>> 
>> 


Re: REST API - Basic Authentication?

Posted by Jeremy Ross <je...@gmail.com>.
I discovered that exchange headers are used for HTTP headers. Setting a
header called `Authorization` on the exchange to `Basic <base64encode(un +
":" + pw)>` worked for me.

On Tue, May 12, 2020 at 11:55 AM Alex Soto <al...@envieta.com> wrote:

> Hello,
>
> I am facing the same issue,  using Camel Rest DSL on top of Servlet,
> Blueprint, Karaf, Pax-Web, Jetty, how to add Basic authentication to the
> Rest endpoints?   Any pointers/examples will be appreciated.
>
>
> Best regards,
> Alex soto
>
>
>
>
> > On Feb 4, 2020, at 3:15 AM, Gerald Kallas - mailbox.org <
> catshout@mailbox.org> wrote:
> >
> > Tx JB.
> >
> > At the moment I decided to register a servlet to re-use the global Jetty
> configuration.
> >
> > So where I can find the filter stuff?
> >
> > For best practices ..
> >
> > 1. better to use servlet or camel-jetty?
> > 2. one servlet for multiple APIs or one dedicated servlet for every API?
> >
> > Best
> > - Gerald
> >
> >> Am 04.02.2020 um 05:56 schrieb Jean-Baptiste Onofré <jb...@nanthrax.net>:
> >>
> >> Hi,
> >>
> >> Not sure I follow (related to your previous message): are you using
> >> servlet registration or camel-jetty ?
> >>
> >> On camel-jetty, you can define a security handler.
> >>
> >> Using servlet, you can always register a filter.
> >>
> >> Regards
> >> JB
> >>
> >>> On 03/02/2020 18:34, Gerald Kallas wrote:
> >>> Dear community,
> >>>
> >>> I've following REST API (see below).
> >>>
> >>> How can I add a Basic Authentication to the REST API in Blueprint DSL?
> Any hints are highly welcome.
> >>>
> >>> Best
> >>> - Gerald
> >>>
> >>> Configuration XML ..
> >>>
> >>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
> >>>
> >>>   <reference id="httpService"
> interface="org.osgi.service.http.HttpService"/>
> >>>
> >>>   <bean id="camelHttpTransportServlet"
> class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
> >>>
> >>>   <bean id="servlet"
> class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
> >>>       init-method="register"
> >>>       destroy-method="unregister">
> >>>       <property name="alias" value="/api"/>
> >>>       <property name="httpService" ref="httpService"/>
> >>>       <property name="servlet" ref="camelHttpTransportServlet"/>
> >>>   </bean>
> >>>
> >>> </blueprint>
> >>>
> >>> .. and REST API ..
> >>>
> >>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
> >>>
> >>>   <camelContext id="isp.routes.RST" xmlns="
> http://camel.apache.org/schema/blueprint" streamCache="true">
> >>>
> >>>       <restConfiguration component="servlet" bindingMode="json"
> contextPath="/api" port="443">
> >>>           <dataFormatProperty key="prettyPrint" value="true"/>
> >>>       </restConfiguration>
> >>>
> >>>       <rest path="/say">
> >>>           <get uri="/hello" consumes="application/json"
> id="isp.routes.RST001">
> >>>               <to uri="direct:hello"/>
> >>>           </get>
> >>>           <get uri="/bye" consumes="application/json"
> id="isp.routes.RST002">
> >>>               <to uri="direct:bye"/>
> >>>           </get>
> >>>       </rest>
> >>>
> >>>       <route id="isp.routes.RST003">
> >>>           <from uri="direct:hello"/>
> >>>           <setHeader name="Content-Type">
> >>>               <constant>application/json</constant>
> >>>           </setHeader>
> >>>           <transform>
> >>>               <constant>{"text": "Hello World"}</constant>
> >>>           </transform>
> >>>       </route>
> >>>
> >>>       <route id="isp.routes.RST004">
> >>>           <from uri="direct:bye"/>
> >>>           <setHeader name="Content-Type">
> >>>               <constant>application/json</constant>
> >>>           </setHeader>
> >>>           <transform>
> >>>               <constant>{"text": "Bye World"}</constant>
> >>>           </transform>
> >>>       </route>
> >>>
> >>>   </camelContext>
> >>>
> >>> </blueprint>
> >>>
> >>
> >> --
> >> Jean-Baptiste Onofré
> >> jbonofre@apache.org
> >> http://blog.nanthrax.net
> >> Talend - http://www.talend.com
> >
>
>

Re: REST API - Basic Authentication?

Posted by Alex Soto <al...@envieta.com>.
Hello,

I am facing the same issue,  using Camel Rest DSL on top of Servlet, Blueprint, Karaf, Pax-Web, Jetty, how to add Basic authentication to the Rest endpoints?   Any pointers/examples will be appreciated. 


Best regards,
Alex soto




> On Feb 4, 2020, at 3:15 AM, Gerald Kallas - mailbox.org <ca...@mailbox.org> wrote:
> 
> Tx JB.
> 
> At the moment I decided to register a servlet to re-use the global Jetty configuration.
> 
> So where I can find the filter stuff?
> 
> For best practices ..
> 
> 1. better to use servlet or camel-jetty?
> 2. one servlet for multiple APIs or one dedicated servlet for every API?
> 
> Best
> - Gerald
> 
>> Am 04.02.2020 um 05:56 schrieb Jean-Baptiste Onofré <jb...@nanthrax.net>:
>> 
>> Hi,
>> 
>> Not sure I follow (related to your previous message): are you using
>> servlet registration or camel-jetty ?
>> 
>> On camel-jetty, you can define a security handler.
>> 
>> Using servlet, you can always register a filter.
>> 
>> Regards
>> JB
>> 
>>> On 03/02/2020 18:34, Gerald Kallas wrote:
>>> Dear community,
>>> 
>>> I've following REST API (see below).
>>> 
>>> How can I add a Basic Authentication to the REST API in Blueprint DSL? Any hints are highly welcome.
>>> 
>>> Best
>>> - Gerald
>>> 
>>> Configuration XML ..
>>> 
>>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>> 
>>>   <reference id="httpService" interface="org.osgi.service.http.HttpService"/>
>>> 
>>>   <bean id="camelHttpTransportServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
>>> 
>>>   <bean id="servlet" class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
>>>       init-method="register"
>>>       destroy-method="unregister">
>>>       <property name="alias" value="/api"/>
>>>       <property name="httpService" ref="httpService"/>
>>>       <property name="servlet" ref="camelHttpTransportServlet"/>
>>>   </bean>
>>> 
>>> </blueprint>
>>> 
>>> .. and REST API ..
>>> 
>>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>> 
>>>   <camelContext id="isp.routes.RST" xmlns="http://camel.apache.org/schema/blueprint" streamCache="true">
>>> 
>>>       <restConfiguration component="servlet" bindingMode="json" contextPath="/api" port="443">
>>>           <dataFormatProperty key="prettyPrint" value="true"/>
>>>       </restConfiguration>
>>> 
>>>       <rest path="/say">
>>>           <get uri="/hello" consumes="application/json" id="isp.routes.RST001">
>>>               <to uri="direct:hello"/>
>>>           </get>
>>>           <get uri="/bye" consumes="application/json" id="isp.routes.RST002">
>>>               <to uri="direct:bye"/>
>>>           </get>
>>>       </rest>
>>> 
>>>       <route id="isp.routes.RST003">
>>>           <from uri="direct:hello"/>
>>>           <setHeader name="Content-Type">
>>>               <constant>application/json</constant>
>>>           </setHeader>
>>>           <transform>
>>>               <constant>{"text": "Hello World"}</constant>
>>>           </transform>
>>>       </route>
>>> 
>>>       <route id="isp.routes.RST004">
>>>           <from uri="direct:bye"/>
>>>           <setHeader name="Content-Type">
>>>               <constant>application/json</constant>
>>>           </setHeader>
>>>           <transform>
>>>               <constant>{"text": "Bye World"}</constant>
>>>           </transform>
>>>       </route>
>>> 
>>>   </camelContext>
>>> 
>>> </blueprint>
>>> 
>> 
>> -- 
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
> 


Re: REST API - Basic Authentication?

Posted by "Gerald Kallas - mailbox.org" <ca...@mailbox.org>.
Tx JB.

At the moment I decided to register a servlet to re-use the global Jetty configuration.

So where I can find the filter stuff?

For best practices ..

1. better to use servlet or camel-jetty?
2. one servlet for multiple APIs or one dedicated servlet for every API?

Best
- Gerald

> Am 04.02.2020 um 05:56 schrieb Jean-Baptiste Onofré <jb...@nanthrax.net>:
> 
> Hi,
> 
> Not sure I follow (related to your previous message): are you using
> servlet registration or camel-jetty ?
> 
> On camel-jetty, you can define a security handler.
> 
> Using servlet, you can always register a filter.
> 
> Regards
> JB
> 
>> On 03/02/2020 18:34, Gerald Kallas wrote:
>> Dear community,
>> 
>> I've following REST API (see below).
>> 
>> How can I add a Basic Authentication to the REST API in Blueprint DSL? Any hints are highly welcome.
>> 
>> Best
>> - Gerald
>> 
>> Configuration XML ..
>> 
>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>> 
>>    <reference id="httpService" interface="org.osgi.service.http.HttpService"/>
>> 
>>    <bean id="camelHttpTransportServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
>> 
>>    <bean id="servlet" class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
>>        init-method="register"
>>        destroy-method="unregister">
>>        <property name="alias" value="/api"/>
>>        <property name="httpService" ref="httpService"/>
>>        <property name="servlet" ref="camelHttpTransportServlet"/>
>>    </bean>
>> 
>> </blueprint>
>> 
>> .. and REST API ..
>> 
>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>> 
>>    <camelContext id="isp.routes.RST" xmlns="http://camel.apache.org/schema/blueprint" streamCache="true">
>> 
>>        <restConfiguration component="servlet" bindingMode="json" contextPath="/api" port="443">
>>            <dataFormatProperty key="prettyPrint" value="true"/>
>>        </restConfiguration>
>> 
>>        <rest path="/say">
>>            <get uri="/hello" consumes="application/json" id="isp.routes.RST001">
>>                <to uri="direct:hello"/>
>>            </get>
>>            <get uri="/bye" consumes="application/json" id="isp.routes.RST002">
>>                <to uri="direct:bye"/>
>>            </get>
>>        </rest>
>> 
>>        <route id="isp.routes.RST003">
>>            <from uri="direct:hello"/>
>>            <setHeader name="Content-Type">
>>                <constant>application/json</constant>
>>            </setHeader>
>>            <transform>
>>                <constant>{"text": "Hello World"}</constant>
>>            </transform>
>>        </route>
>> 
>>        <route id="isp.routes.RST004">
>>            <from uri="direct:bye"/>
>>            <setHeader name="Content-Type">
>>                <constant>application/json</constant>
>>            </setHeader>
>>            <transform>
>>                <constant>{"text": "Bye World"}</constant>
>>            </transform>
>>        </route>
>> 
>>    </camelContext>
>> 
>> </blueprint>
>> 
> 
> -- 
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com


Re: REST API - Basic Authentication?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

Not sure I follow (related to your previous message): are you using
servlet registration or camel-jetty ?

On camel-jetty, you can define a security handler.

Using servlet, you can always register a filter.

Regards
JB

On 03/02/2020 18:34, Gerald Kallas wrote:
> Dear community,
> 
> I've following REST API (see below).
> 
> How can I add a Basic Authentication to the REST API in Blueprint DSL? Any hints are highly welcome.
> 
> Best
> - Gerald
> 
> Configuration XML ..
> 
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
> 
> 	<reference id="httpService" interface="org.osgi.service.http.HttpService"/>
> 
> 	<bean id="camelHttpTransportServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
> 
> 	<bean id="servlet" class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
>         init-method="register"
>         destroy-method="unregister">
> 		<property name="alias" value="/api"/>
> 		<property name="httpService" ref="httpService"/>
> 		<property name="servlet" ref="camelHttpTransportServlet"/>
> 	</bean>
> 
> </blueprint>
> 
> .. and REST API ..
> 
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
> 
> 	<camelContext id="isp.routes.RST" xmlns="http://camel.apache.org/schema/blueprint" streamCache="true">
> 
> 		<restConfiguration component="servlet" bindingMode="json" contextPath="/api" port="443">
> 			<dataFormatProperty key="prettyPrint" value="true"/>
> 		</restConfiguration>
> 
> 		<rest path="/say">
> 			<get uri="/hello" consumes="application/json" id="isp.routes.RST001">
> 				<to uri="direct:hello"/>
> 			</get>
> 			<get uri="/bye" consumes="application/json" id="isp.routes.RST002">
> 				<to uri="direct:bye"/>
> 			</get>
> 		</rest>
> 
> 		<route id="isp.routes.RST003">
> 			<from uri="direct:hello"/>
> 			<setHeader name="Content-Type">
> 				<constant>application/json</constant>
> 			</setHeader>
> 			<transform>
> 				<constant>{"text": "Hello World"}</constant>
> 			</transform>
> 		</route>
> 
> 		<route id="isp.routes.RST004">
> 			<from uri="direct:bye"/>
> 			<setHeader name="Content-Type">
> 				<constant>application/json</constant>
> 			</setHeader>
> 			<transform>
> 				<constant>{"text": "Bye World"}</constant>
> 			</transform>
> 		</route>
> 
> 	</camelContext>
> 
> </blueprint>
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com