REST API - Basic Authentication?

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

REST API - Basic Authentication?

Gerald Kallas - mailbox.org
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>
Reply | Threaded
Open this post in threaded view
|

Re: REST API - Basic Authentication?

jbonofre
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é
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: REST API - Basic Authentication?

Gerald Kallas - 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é <[hidden email]>:
>
> 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é
> [hidden email]
> http://blog.nanthrax.net
> Talend - http://www.talend.com

Reply | Threaded
Open this post in threaded view
|

Re: REST API - Basic Authentication?

Alex Soto
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 <[hidden email]> 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é <[hidden email]>:
>>
>> 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é
>> [hidden email]
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>

Reply | Threaded
Open this post in threaded view
|

Re: REST API - Basic Authentication?

Jeremy Ross
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 <[hidden email]> 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 <
> [hidden email]> 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é <[hidden email]>:
> >>
> >> 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é
> >> [hidden email]
> >> http://blog.nanthrax.net
> >> Talend - http://www.talend.com
> >
>
>
Reply | Threaded
Open this post in threaded view
|

Re: REST API - Basic Authentication?

Alex Soto
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 <[hidden email]> 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 <[hidden email]> 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 <
>> [hidden email]> 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é <[hidden email]>:
>>>>
>>>> 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é
>>>> [hidden email]
>>>> http://blog.nanthrax.net
>>>> Talend - http://www.talend.com
>>>
>>
>>