users@jersey.java.net

[Jersey] Fwd: Re: Re: Jersey oAuth services provider -> ignorePattern not working

From: Martin Matula <martin.matula_at_oracle.com>
Date: Wed, 20 Jul 2011 17:36:28 +0200

fwding to the mailing list for the benefit of others

-------- Original Message --------
Subject: Re: [Jersey] Re: Jersey oAuth services provider ->
ignorePattern not working
Date: Wed, 20 Jul 2011 15:35:32 +0100 (BST)
From: Corben <corben80_at_yahoo.it>
Reply-To: Corben <corben80_at_yahoo.it>
To: Martin Matula <martin.matula_at_oracle.com>



Oh thank God!

You saved the day!!!!!!!!!!!!! :-P


Can you reply this last mail in the mailing list? So other people that might have the same problem in the future can find it out easily... Or I can post your reply if you want...

Thanks again!!
Corben




----- Messaggio originale -----
Da: Martin Matula<martin.matula_at_oracle.com>
A: Corben<corben80_at_yahoo.it>
Cc:
Inviato: Mercoledì 20 Luglio 2011 16:22
Oggetto: Re: [Jersey] Re: Jersey oAuth services provider -> ignorePattern not working

Ah, this may be the difference in servlet vs. filter behavior. If you
are not using root, there is no point in having the following element in
the web.xml:

              <init-param>
                  <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
                  <param-value>.*\.css|.*\.png|.*\.jsp</param-value>
              </init-param>

And I believe it will start working when you change the registration from filter to servlet (it is needed to be configured as a filter if it is put at root for the jsp templates to work, but once you don't have it at root, it can be a servlet). I suspect that as long as it is a filter, the prefix (/oAuth) is part of the resource path and that's why your resources are not getting resolved (since you would have to change the path templates to include the oAuth prefix). If you change the registration to servlet (in case of using /oAuth/* prefix), it should work.
I.e. in web.xml replace:
<filter> with<servlet>
<filter-name> with<servlet-name>
<filter-class> with<servlet-class>
<filter-mapping> with<servlet-mapping>

Regards,
Martin




On 20.7.2011 14:40, Corben wrote:
>> OK, so in case you are mapping the filter to /*, it works properly
>> (protected resources are protected and resources from the ignore pattern
>> are ignored by the oauth filter) - correct?
> Correct!!
>
>> Now, after you change the url pattern to /oAuth/*, what are the URL's
>> that give you error?
> All of them are returning 404 Not found, even if I log in the filter and I can see that the pattern matches the ignorePattern, so the request is "returned" correctly from the filter to the Container.
> With all of them I mean both oAuth Jersey resources:
> /oAuth/requestToken
> /oAuth/accessToken
> And my resources:
> /oAuth/services/method1
> /oAuth/services/method2
> /oAuth/services/method3
> /oAuth/services/method4
> /oAuth/authorize
>
>> Do the URL's without /oAuth give you error or do they work?
> Yes, I tried some JSPs and they work, e.g. localhost:8080/MyProject/index.jsp (note that when instead I deploy the filter in the root /* the index.jsp stop answering)
>
>> Can you check if what's deployed in tomcat matches what you think is
>> deployed?
> Checked: Tomcat is ok, the WAR file is there, with all the needed .class, and web.xml, and jsps, etc.
>
> Thank you so much for your support!!
>
> Corben
>
>
>
>
> ----- Messaggio originale -----
> Da: Martin Matula<martin.matula_at_oracle.com>
> A: Corben<corben80_at_yahoo.it>
> Cc:
> Inviato: Mercoledì 20 Luglio 2011 14:31
> Oggetto: Re: [Jersey] Re: Jersey oAuth services provider -> ignorePattern not working
>
> OK, so in case you are mapping the filter to /*, it works properly
> (protected resources are protected and resources from the ignore pattern
> are ignored by the oauth filter) - correct?
> Now, after you change the url pattern to /oAuth/*, what are the URL's
> that give you error?
> Do the URL's without /oAuth give you error or do they work?
> Can you check if what's deployed in tomcat matches what you think is
> deployed? (i.e. the web.xml is correct) Also you may want to try
> restarting tomcat.
> Martin
>
> On 20.7.2011 14:25, Corben wrote:
>> Hi Martin,
>>
>> thanks for your advice...
>>
>> I tried and indeed services are deployed... But still I get the same problem:
>> <filter-mapping>
>> <filter-name>Jersey Filter</filter-name>
>> <url-pattern>/*</url-pattern>
>> </filter-mapping>
>> Works correctly, while if I move it to:
>> <filter-mapping>
>> <filter-name>Jersey Filter</filter-name>
>> <url-pattern>/oAuth/*</url-pattern>
>> </filter-mapping>
>>
>> I get a 404 Not Found error on every web service call, even if I can see that the filter is allowing the request to pass...
>> What do you suggest?
>> Thanks!!
>> Corben
>>
>>
>>
>>
>>
>> ----- Messaggio originale -----
>> Da: Martin Matula<martin.matula_at_oracle.com>
>> A: users_at_jersey.java.net
>> Cc:
>> Inviato: Mercoledì 20 Luglio 2011 14:16
>> Oggetto: [Jersey] Re: Jersey oAuth services provider -> ignorePattern not working
>>
>> Hi,
>> Please remove the servlet element from your web.xml - see below:
>>
>> On 20.7.2011 11:29, Corben wrote:
>>> Dear all,
>>>
>>> I have a problem in using the oAuth filter, while implementing an oAuth Service Provider.
>>> My setup is: Tomcat 7, Jersey 1.8, development under Eclipse.
>>>
>>>
>>> The resources that I expose are:
>>> /services/... where I have 4 jersey REST WS that I want to protect with oAuth (defined and annotated in MyServlet)
>>>
>>> /authorize providing a resource to authorize a request token
>>>
>>> And of course I have the two WS exposed by the Jersey oAuth library:
>>> /requestToken
>>> /accessToken
>>>
>>>
>>> Here is my web.xml file:
>>> [code]
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
>>> <display-name>MyProjectPhrJersey</display-name>
>>> <welcome-file-list>
>>> <welcome-file>index.html</welcome-file>
>>> <welcome-file>index.htm</welcome-file>
>>> <welcome-file>portal/index.jsp</welcome-file>
>>> <welcome-file>default.html</welcome-file>
>>> <welcome-file>default.htm</welcome-file>
>>> <welcome-file>default.jsp</welcome-file>
>>> </welcome-file-list>
>>>
>>> <filter>
>>> <filter-name>Jersey Filter</filter-name>
>>> <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
>>> <param-value>/WEB-INF</param-value>
>>> </init-param>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
>>> <param-value>.*\.css|.*\.png|.*\.jsp</param-value>
>>> </init-param>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.feature.Redirect</param-name>
>>> <param-value>true</param-value>
>>> </init-param>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.property.packages</param-name>
>>> <param-value>com.mypackage, com.sun.jersey.oauth.server.api.resources</param-value>
>>> </init-param>
>>> <init-param>
>>> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
>>> <param-value>com.sun.jersey.oauth.server.api.OAuthServerFilter</param-value>
>>> </init-param>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.property.oauth.provider</param-name>
>>> <param-value>com.mypackage.MyProvider</param-value>
>>> </init-param>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.property.oauth.ignorePathPattern</param-name>
>>> <param-value>requestToken|authorize|accessToken</param-value>
>>> </init-param>
>>> </filter>
>>> <filter-mapping>
>>> <filter-name>Jersey Filter</filter-name>
>>> <url-pattern>/*</url-pattern>
>>> </filter-mapping>
>>>
>> !!! --- REMOVE THE FOLLOWING ---
>>> <servlet>
>>> <servlet-name>MyServlet</servlet-name>
>>> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.property.packages</param-name>
>>> <param-value>com.mypackage.MyProvider</param-value>
>>> </init-param>
>>> <load-on-startup>1</load-on-startup>
>>> </servlet>
>>> <servlet-mapping>
>>> <servlet-name>MyServlet</servlet-name>
>>> <url-pattern>/*</url-pattern>
>>> </servlet-mapping>
>> !!! --- REMOVE THE ABOVE ---
>>
>> Regards,
>> Martin