mam-dev / cosmo

Cosmo Calendar Server implements the server side of the CalDAV protocol.
Apache License 2.0
77 stars 45 forks source link

Fixed regular expressions to be able to handle prefixed pathes. #37

Open k-oliver opened 4 years ago

k-oliver commented 4 years ago

Hi, I'm using cosmo embedded in an OSGi enviroment where all servlets and filters are prefixed with pathes like /calendar. When using tickets the given path is used to find resources. This results in errors like this: TicketedItemNotFoundException: Resource at /calendar/dav/item/99a0533b-0035-47f0-a6d1-acb96218811e not found

I tried different Spring solutions like adding Springs ForwardedHeaderFilter. But none worked because the finally the TicketProcessingFilter uses httpRequest.getPathInfo() which always gets the full path.

With this PR i suggest to make the path parsing using the resource pathes more tollerant by allowing prefixed pathes. This make tickets work again for me.

The regular expressions now can handle pathes like: /something/item/... /item/... /another/user/... /user /any/prefix/path/collection/..

danielgrigore commented 4 years ago

Hi @k-oliver

I had a look at your comments and also checked our application. (It is true that our application is not running in an OSGI environment) I understand that you run your application in an OSGI environment and you have to prefix your contexts/servlets but in the example shown it seems that you have a different problem. The path given as example is this one:/calendar/dav/item/99a0533b-0035-47f0-a6d1-acb96218811e

If I assume correctly :

You say that you always get the full path in TicketProcessingFilter, but according to Servlet API the method getPathInfo from HttpServletRequest

Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character.

How is it possible that you get the full path including application context and servlet context ? What container/servlet version are you using ?

Thanks.

k-oliver commented 4 years ago

Hi @danielgrigore , servlet context is /calendar/dav. I'm using Jetty 9.x with servlet 3.1.

danielgrigore commented 4 years ago

Hi @k-oliver

I modified the demo cosmo-webapp to use jetty (9.4.19) instead of tomcat and decreased the Servlet API version from 4.0.1 to 3.10. Then I created a collection, an item and a ticket and tried to access the item using the newly generated ticket. Everything worked fine. The curl command looked like curl -i -XGET -H"Ticket: ..." http://localhost:8080/cosmo/dav/item/f12946ee-b50d-4c0b-96e5-3404bb82df5b

In your situation is it possible to use an incorrect URL for getting the event ? From your message it seems that the incorrect URL might be something like http://localhost:8080/calendar/dav/calendar/dav/item/f12946ee-b50d-4c0b-96e5-3404bb82df5b Cheers,