Thanks Tim,

My bad not explaining the situation well, it's actually not the filter
itself but rather what the filter uses that prevent me from using
whiteboard .
My servlet filter is using some attributes on the request set by keycloak
authenticator:

public void doFilter(final ServletRequest request, final ServletResponse
response, final FilterChain chain)
throws IOException, ServletException {

Object kcSecurityContext =
request.getAttribute(KeycloakSecurityContext.class.getName());

Keycloak authenticator is registered with the web container by the
following tag in web.xml:
<login-config>
        <auth-method>KEYCLOAK</auth-method>
        <realm-name>realm1</realm-name>
    </login-config>
it also need a special json file in the WEB-INF providing info about of the
authentication server.
The keycloak authenticator seem to be applied to the whole web app instead
of a servlet.


Thai

On Tue, Aug 7, 2018 at 11:37 AM, Tim Ward <tim.w...@paremus.com> wrote:

> You are aware that Servlet Filters are also supported by the whiteboard?
> See https://osgi.org/specification/osgi.cmpn/7.0.0/
> service.http.whiteboard.html#d0e121055
>
> Just to reiterate my warning, continuing to develop a WAB will
> significantly affect your ability to reliably take advantage of OSGi
> specifications and services from your web code going forward. If you do
> have more problems then you will likely find that the future advice from
> this list is that you should migrate away from using a WAB.
>
> Best Regards,
>
> Tim
>
> On 7 Aug 2018, at 16:12, Nhut Thai Le <n...@castortech.com> wrote:
>
> Thanks Tim,
>
> I'll stick with the WAB for now and use the BundleContext to get my
> service since I need to config some security filter on the web.xml.
>
> Thai
>
> On Tue, Aug 7, 2018 at 4:15 AM, Tim Ward <tim.w...@paremus.com> wrote:
>
>> Hi,
>>
>> I’m afraid that if you’re using a WAB file then you absolutely can’t use
>> DS, and vice versa. The Web Application Bundle specification exists as a
>> mechanism to allow people to move from a non-OSGi world into OSGi, and
>> there are a number of restrictions as a result. The one that you’re hitting
>> is that in a Web Application the Servlet container is responsible for
>> instantiating and managing the lifecycle of the Servlet instances. As a
>> result you are getting two instances created, one by DS which is injecting
>> the AdminBroker service, and one by the Servlet Container which isn’t
>> injecting anything.
>>
>> Assuming that this is a new project then by far the simplest way to fix
>> this is to completely avoid making a WAB, and just to use the Http
>> Whiteboard. This will simplify things immensely, and handle the service
>> dynamics easily. If you can’t avoid using the WAB then you do have access
>> to the BundleContext in your ServletContext (see
>> https://osgi.org/specification/osgi.cmpn/7.0.0/service.war.html#d0e101441).
>> You would have to use this to get the service you want to use (and release
>> it, and deal with what happens if it isn’t available).
>>
>> In summary, WABs exist for specific use cases when you can’t be properly
>> modular, or for when you have to work both inside and outside OSGi. It’s
>> not recommended to use them as your first development option.
>>
>> I wish you luck with your experiments!
>>
>> Best Regards,
>>
>> Tim
>>
>> On 6 Aug 2018, at 22:10, Nhut Thai Le <n...@castortech.com> wrote:
>>
>> Hi Tim,
>>
>> The servlet is inside a WAB file which has a web.xml:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <web-app xmlns="http://java.sun.com/xml/ns/javaee";
>>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>>          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";
>>          version="3.0">
>> <servlet>
>> <servlet-name>HelloWorld</servlet-name>
>> <servlet-class>com.webapp.HelloWorld</servlet-class>
>> </servlet>
>>
>> <servlet-mapping>
>> <servlet-name>HelloWorld</servlet-name>
>> <url-pattern>/</url-pattern>
>> </servlet-mapping>
>> </web-app>
>>
>> I'm not trying to use the whiteboard pattern in the first place but
>> rather looking for a way to inject my AdminBroker service into my servlet
>> so I turn my servlet into a component in order to use the reference.
>>
>> Thai
>>
>>
>> On Mon, Aug 6, 2018 at 4:44 PM, Tim Ward <tim.w...@paremus.com> wrote:
>>
>>> I don’t see any Http Service whiteboard properties on the Servlet
>>> component. How are you registering it with the Servlet container?
>>>
>>> Tim
>>>
>>> Sent from my iPhone
>>>
>>> On 6 Aug 2018, at 16:22, Nhut Thai Le via osgi-dev <
>>> osgi-dev@mail.osgi.org> wrote:
>>>
>>> Hello,
>>>
>>> I have a servlet defined like this:
>>>
>>> @Component(service = Servlet.class)
>>> public class HelloWorld extends HttpServlet {
>>> @Reference(cardinality = ReferenceCardinality.MANDATORY)
>>> private AdminBroker adminBroker;
>>>
>>> protected void doGet(HttpServletRequest request, HttpServletResponse
>>> response) throws ServletException, IOException {
>>> adminBroker.doSomething();
>>> }
>>> }
>>>
>>> My AdminBroker implementation looks like:
>>> @Component(service=AdminBroker.class)
>>> public class AdminBrokerImpl implements AdminBroker {
>>> @Activate
>>> private void init() {
>>> String param1 = "some text";
>>> }
>>> }
>>>
>>> When I started the env (felix 6 with pax-web), I can see the AdminBroker
>>> instantiated (hit a break point in the init of my AdminBroker
>>> implementation) but when the web request arrives and the doGet method is
>>> called, the adminBroker is null.
>>>
>>> Does anyone have an idea what may go wrong here?
>>>
>>> Thai Le
>>>
>>> --
>>> Castor Technologies Inc
>>> 460 rue St-Catherine St
>>> <https://maps.google.com/?q=460+rue+St-Catherine+St&entry=gmail&source=g>
>>> Ouest, Suite 613
>>> Montréal, Québec H3B-1A7
>>> (514) 360-7208 o
>>> (514) 798-2044 f
>>> n...@castortech.com
>>> www.castortech.com
>>>
>>> CONFIDENTIALITY NOTICE: The information contained in this e-mail is
>>> confidential and may be proprietary information intended only for the use
>>> of the individual or entity to whom it is addressed. If the reader of this
>>> message is not the intended recipient, you are hereby notified that any
>>> viewing, dissemination, distribution, disclosure, copy or use of the
>>> information contained in this e-mail message is strictly prohibited. If you
>>> have received and/or are viewing this e-mail in error, please immediately
>>> notify the sender by reply e-mail, and delete it from your system without
>>> reading, forwarding, copying or saving in any manner. Thank you.
>>> AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est
>>> confidentiel, peut être protégé par le secret professionnel et est réservé
>>> à l'usage exclusif du destinataire. Toute autre personne est par les
>>> présentes avisée qu'il lui est strictement interdit de diffuser, distribuer
>>> ou reproduire ce message. Si vous avez reçu cette communication par erreur,
>>> veuillez la détruire immédiatement et en aviser l'expéditeur. Merci.
>>>
>>> _______________________________________________
>>> OSGi Developer Mail List
>>> osgi-dev@mail.osgi.org
>>> https://mail.osgi.org/mailman/listinfo/osgi-dev
>>>
>>>
>>
>>
>> --
>> Castor Technologies Inc
>> 460 rue St-Catherine St
>> <https://maps.google.com/?q=460+rue+St-Catherine+St&entry=gmail&source=g>
>> Ouest, Suite 613
>> Montréal, Québec H3B-1A7
>> (514) 360-7208 o
>> (514) 798-2044 f
>> n...@castortech.com
>> www.castortech.com
>>
>> CONFIDENTIALITY NOTICE: The information contained in this e-mail is
>> confidential and may be proprietary information intended only for the use
>> of the individual or entity to whom it is addressed. If the reader of this
>> message is not the intended recipient, you are hereby notified that any
>> viewing, dissemination, distribution, disclosure, copy or use of the
>> information contained in this e-mail message is strictly prohibited. If you
>> have received and/or are viewing this e-mail in error, please immediately
>> notify the sender by reply e-mail, and delete it from your system without
>> reading, forwarding, copying or saving in any manner. Thank you.
>> AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est
>> confidentiel, peut être protégé par le secret professionnel et est réservé
>> à l'usage exclusif du destinataire. Toute autre personne est par les
>> présentes avisée qu'il lui est strictement interdit de diffuser, distribuer
>> ou reproduire ce message. Si vous avez reçu cette communication par erreur,
>> veuillez la détruire immédiatement et en aviser l'expéditeur. Merci.
>>
>>
>>
>
>
> --
> Castor Technologies Inc
> 460 rue St-Catherine St
> <https://maps.google.com/?q=460+rue+St-Catherine+St&entry=gmail&source=g>
> Ouest, Suite 613
> Montréal, Québec H3B-1A7
> (514) 360-7208 o
> (514) 798-2044 f
> n...@castortech.com
> www.castortech.com
>
> CONFIDENTIALITY NOTICE: The information contained in this e-mail is
> confidential and may be proprietary information intended only for the use
> of the individual or entity to whom it is addressed. If the reader of this
> message is not the intended recipient, you are hereby notified that any
> viewing, dissemination, distribution, disclosure, copy or use of the
> information contained in this e-mail message is strictly prohibited. If you
> have received and/or are viewing this e-mail in error, please immediately
> notify the sender by reply e-mail, and delete it from your system without
> reading, forwarding, copying or saving in any manner. Thank you.
> AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est
> confidentiel, peut être protégé par le secret professionnel et est réservé
> à l'usage exclusif du destinataire. Toute autre personne est par les
> présentes avisée qu'il lui est strictement interdit de diffuser, distribuer
> ou reproduire ce message. Si vous avez reçu cette communication par erreur,
> veuillez la détruire immédiatement et en aviser l'expéditeur. Merci.
>
>
>


-- 
Castor Technologies Inc
460 rue St-Catherine St Ouest, Suite 613
Montréal, Québec H3B-1A7
(514) 360-7208 o
(514) 798-2044 f
n...@castortech.com
www.castortech.com

CONFIDENTIALITY NOTICE: The information contained in this e-mail is
confidential and may be proprietary information intended only for the use
of the individual or entity to whom it is addressed. If the reader of this
message is not the intended recipient, you are hereby notified that any
viewing, dissemination, distribution, disclosure, copy or use of the
information contained in this e-mail message is strictly prohibited. If you
have received and/or are viewing this e-mail in error, please immediately
notify the sender by reply e-mail, and delete it from your system without
reading, forwarding, copying or saving in any manner. Thank you.
AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est
confidentiel, peut être protégé par le secret professionnel et est réservé
à l'usage exclusif du destinataire. Toute autre personne est par les
présentes avisée qu'il lui est strictement interdit de diffuser, distribuer
ou reproduire ce message. Si vous avez reçu cette communication par erreur,
veuillez la détruire immédiatement et en aviser l'expéditeur. Merci.
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to