hstaudacher / osgi-jax-rs-connector

An OSGi - JAX-RS 2.0 Connector, software repository available on the link below
http://hstaudacher.github.io/osgi-jax-rs-connector
Other
191 stars 98 forks source link

ServletFilter do not work? #99

Closed Sandared closed 9 years ago

Sandared commented 9 years ago

Hi,

first of all: thanks for this project :+1: It's good to see Jersey integrated in a lightweight way ;)

Nevertheless, I have one problem: I tried to integrate Apache Shiro in my project to secure my application, but the ShiroFilter, which should intercept unauthorized access, is not activated when I try to access a Resource created with the osgi-jax-rs-connector. Nor is my dummy Filter, which I created for testing purposes.

Both are registered in OSGi via the properties:

@Property(name="osgi.http.whiteboard.filter.name", value="MyFilter") @Property(name="osgi.http.whiteboard.filter.pattern", value="/*")

I'm currently using Felix as OSGi implementation.

Do you have any advice on this? My first guess would be, that my filters and resources are registered under different ServletContexts, but I don't know where to debug to see which ServletContext is used by the registered resources.

Best regards, Thomas

hstaudacher commented 9 years ago

Phew, I have no idea how I can help you. I would suggest that you take a look at our security integration. It uses also a servlet filter as far as I know.

Sandared commented 9 years ago

After some investigation work I traced the problem down to Felix' implementation of the HttpService. I don't know yet if it's a bug or an intended behaviour.

In your code you use HttpService.registerServlet() in the class jerseyContext to register a Servlet explicitly. The new OSGi EE R6 compliant way would be to publish the servlet with two properties, osgi.http.whiteboard.servlet.name and osgi.http.whiteboard.servlet.pattern, as a service to the registry. Afterwards it gets picked up by felix.http.jetty, I think, and is registered as a Servlet.

These two approaches seem not to work in combination (the mentioned Felix Issue), as they create two differen ServletContexts (I always thought there is only one per Servlet Container?)

Are there any thoughts on updating the connector in order to publish the servlets the new way?

Best regards, Thomas

hstaudacher commented 9 years ago

Good Point. Some users made a huge effort to backport the connector to OSGi R4 #49. So, we have to find a proper solution here.

I think it's necessary to support the HttpService whiteboard pattern as it will replace the old way in the future. Maybe we can find out at runtime which version of the OSGi spec runs and do the one thing or the other. Do you have any other idea?

Sandared commented 9 years ago

Hi Holger,

I also opened an issue on the Apache Felix mailing list, regarding this topic: http://www.mail-archive.com/users%40felix.apache.org/msg16346.html

They opened an issue in Jira for the problem: https://issues.apache.org/jira/browse/FELIX-4904. The root of the problem seems to be the different ServletContexts. Servlets/Filters registered via the new whiteboard style are using a different one than those registered directly via HttpService. As I'm a newbe to both OSGi and JEE(Servlets/Filters and such stuff) and am still struggeling with some concepts, maybe you can add something worthy to this discussion on the Felix mailing list :)

I'm busy with other stuff for the next few days, but I will try to solve this problem in the next week :)

Best regards, Thomas

2015-05-23 13:25 GMT+02:00 Holger Staudacher notifications@github.com:

Good Point. Some users made a huge effort to backport the connector to OSGi R4 #49 https://github.com/hstaudacher/osgi-jax-rs-connector/pull/49. So, we have to find a proper solution here.

I think it's necessary to support the HttpService whiteboard pattern as it will replace the old way in the future. Maybe we can find out at runtime which version of the OSGi spec runs and do the one thing or the other. Do you have any other idea?

— Reply to this email directly or view it on GitHub https://github.com/hstaudacher/osgi-jax-rs-connector/issues/99#issuecomment-104883537 .

hstaudacher commented 9 years ago

Hey Thomas, I think there is nothing to add. You said it all. If the specification does not define that the whiteboard approach should use other contexts this is a bug because both ways need to be compatible. If the felix guys agree I see no point in registering the Connector via whiteboard to be compatible with R4.

hstaudacher commented 9 years ago

I assume since the felix issue is marked as fixed we can close this too, right? Please feel free to reopen if not.