ContainerRequestFilter not triggered on subresource

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

ContainerRequestFilter not triggered on subresource

Rémi AUBEL
Hi,

My application uses CXF 3.1.10 and I use ContainerRequestFilters to manage authentication and authorization.
I have both resources and subresources.

When my controller returns directly a resource, the filters are correctly called.
But when a subresource is matched, they are not.

Is it a normal behavior? Did I forget some configuration somewhere?

Thanks & Regards

Rémi.
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Hi

I've checked the code, the filters should be executed on a subresource
locator method. Are you sure these are not PreMatching filters ?

Thanks, Sergey
On 05/05/17 16:07, Rémi AUBEL wrote:

> Hi,
>
> My application uses CXF 3.1.10 and I use ContainerRequestFilters to manage
> authentication and authorization.
> I have both resources and subresources.
>
> When my controller returns directly a resource, the filters are correctly
> called.
> But when a subresource is matched, they are not.
>
> Is it a normal behavior? Did I forget some configuration somewhere?
>
> Thanks & Regards
>
> Rémi.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Rémi AUBEL

Hi Sergey,

Thanks for the reply.
In fact, if my filters are annotated with @PreMatching, they are triggered on the subresource locator method. But post-matching ones are not.
It this expected? Because I prefer to stick with post-matching filters...

Thanks,
Rémi. 

Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Hi Rémi

Can you please download CXF 3.1.10 JAXRS code [1] and put a breakpoint
at [2] ?

I do not see how pre-matching filters can be still executed

Thanks, Sergey

[1]
https://search.maven.org/remotecontent?filepath=org/apache/cxf/cxf-rt-frontend-jaxrs/3.1.10/cxf-rt-frontend-jaxrs-3.1.10-sources.jar
[2]
https://github.com/apache/cxf/blob/master/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java#L248

On 06/05/17 07:50, Rémi AUBEL wrote:

> Hi Sergey,
>
> Thanks for the reply.
> In fact, if my filters are annotated with @PreMatching, they are triggered
> on the subresource locator method. But post-matching ones are not.
> It this expected? Because I prefer to stick with post-matching filters...
>
> Thanks,
> Rémi.
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780255.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Or prepare a test if you prefer

Thanks, Sergey
On 08/05/17 13:23, Sergey Beryozkin wrote:

> Hi Rémi
>
> Can you please download CXF 3.1.10 JAXRS code [1] and put a breakpoint
> at [2] ?
>
> I do not see how pre-matching filters can be still executed
>
> Thanks, Sergey
>
> [1]
> https://search.maven.org/remotecontent?filepath=org/apache/cxf/cxf-rt-frontend-jaxrs/3.1.10/cxf-rt-frontend-jaxrs-3.1.10-sources.jar
>
> [2]
> https://github.com/apache/cxf/blob/master/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java#L248
>
>
> On 06/05/17 07:50, Rémi AUBEL wrote:
>> Hi Sergey,
>>
>> Thanks for the reply.
>> In fact, if my filters are annotated with @PreMatching, they are
>> triggered
>> on the subresource locator method. But post-matching ones are not.
>> It this expected? Because I prefer to stick with post-matching filters...
>>
>> Thanks,
>> Rémi.
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780255.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Rémi AUBEL
Hi Sergey,

I guess that pre-match filters are executed because of these lines in JAXRSInInteceptor.processRequest():
        // Global pre-match request filters
        if (JAXRSUtils.runContainerRequestFilters(providerFactory, message, true, null)) {
            return;
        }

BTW, my platform has been upgraded recently: I'm using CXF 3.1.11 (instead of 3.1.10 as I previously told you).

Thanks,
Rémi.

Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Hi Rémi

Yes, the pre-match filters are indeed executed there, because at that
point no resource method has been matched yet.

Can you prototype your resource class and the filter (without the impl
details) and explain at what point you expect the filter to be invoked ?

Sergey
On 09/05/17 08:32, Rémi AUBEL wrote:

> Hi Sergey,
>
> I guess that pre-match filters are executed because of these lines in
> JAXRSInInteceptor.processRequest():
>
>
> BTW, my platform has been upgraded recently: I'm using CXF 3.1.11 (instead
> of 3.1.10 as I previously told you).
>
> Thanks,
> Rémi.
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780303.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Rémi AUBEL
Please find below my resource, subresource and filter classes (implementation removed).

@Path("app")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ApplicationController {

	@Context
	private ResourceContext resourceContext;

	public ApplicationController() {}

	@GET
	public Resource getApplicationInfo() {
		return getResource();
	}

	@Path("nav")
	public NavigationDrawerController getNavigationDrawer() {
		return resourceContext.initResource(new NavigationDrawerController());
	}
}

@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class NavigationDrawerController {

	@GET
	public Resource getNavigationDrawerInfo() {
		return getResource();
	}

}

@Provider
@PreMatching
@Priority(Priorities.AUTHENTICATION + 1)
public class AuthenticationJaxrsFilter implements ContainerRequestFilter {

	@Override
	public void filter(ContainerRequestContext context) throws IOException {
		System.out.println("AuthenticationServletFilter triggered");
	}

}

My post-matching filter is called when "app" is matched, but not when "app/nav" is matched.
(Yet both requests are served correctly.)

Thanks,
Rémi.
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Thanks. You do not have a post-matching filter, you only have a
pre-matching filter.

Cheers, Sergey
On 09/05/17 12:51, Rémi AUBEL wrote:

> Please find below my resource, subresource and filter classes (implementation
> removed).
>
>
>
>
>
>
>
> My post-matching filter is called when "app" is matched, but /not/ when
> "app/nav" is matched.
> (Yet both requests are served correctly.)
>
> Thanks,
> Rémi.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780317.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Rémi AUBEL
Sorry, while prototyping my code, I've not removed the @PreMatching annotation that I have put recently to have my filter invoked for every method.
The facts are:
- my filter is invoked for "app" and "app/nav" if it is annotated with @PreMatching
- it is invoked for "app" only if it is not annotated
But I still want to have a post-matching filter invoked for both methods.
Any solution/explanation?

Regards,
Rémi.
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Np, I think you've found a bug which will need to be addressed

Thanks, Sergey
On 09/05/17 13:09, Rémi AUBEL wrote:

> Sorry, while prototyping my code, I've not removed the @PreMatching
> annotation that I have put recently to have my filter invoked for every
> method.
> The facts are:
> - my filter is invoked for "app" and "app/nav" if it is annotated with
> @PreMatching
> - it is invoked for "app" only if it is not annotated
> But I still want to have a post-matching filter invoked for both methods.
> Any solution/explanation?
>
> Regards,
> Rémi.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780319.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Wait, I'm getting confused now, I'll need to do a test...

Sergey
On 09/05/17 13:25, Sergey Beryozkin wrote:

> Np, I think you've found a bug which will need to be addressed
>
> Thanks, Sergey
> On 09/05/17 13:09, Rémi AUBEL wrote:
>> Sorry, while prototyping my code, I've not removed the @PreMatching
>> annotation that I have put recently to have my filter invoked for every
>> method.
>> The facts are:
>> - my filter is invoked for "app" and "app/nav" if it is annotated with
>> @PreMatching
>> - it is invoked for "app" only if it is not annotated
>> But I still want to have a post-matching filter invoked for both methods.
>> Any solution/explanation?
>>
>> Regards,
>> Rémi.
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780319.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
app/nav method def will not be filtered - it is a subresource locator,
but the method on the found subresource will have to be filtered - can
you confirm please that

getNavigationDrawerInfo

is filtered ?

Thanks, Sergey
On 09/05/17 13:28, Sergey Beryozkin wrote:

> Wait, I'm getting confused now, I'll need to do a test...
>
> Sergey
> On 09/05/17 13:25, Sergey Beryozkin wrote:
>> Np, I think you've found a bug which will need to be addressed
>>
>> Thanks, Sergey
>> On 09/05/17 13:09, Rémi AUBEL wrote:
>>> Sorry, while prototyping my code, I've not removed the @PreMatching
>>> annotation that I have put recently to have my filter invoked for every
>>> method.
>>> The facts are:
>>> - my filter is invoked for "app" and "app/nav" if it is annotated with
>>> @PreMatching
>>> - it is invoked for "app" only if it is not annotated
>>> But I still want to have a post-matching filter invoked for both
>>> methods.
>>> Any solution/explanation?
>>>
>>> Regards,
>>> Rémi.
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780319.html
>>>
>>>
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>
>>
>
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Rémi AUBEL
Unfortunately, the filter is not invoked at all, neither for the subresource locator, nor for the method of the subresource itself (getNavigationDrawerInfo).

Rémi.
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Rémi AUBEL
Hi Sergey,

For information, I have created issue CXF-7367.

Thanks for your time,
Rémi.
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Hi

I've added the following test confirming it works with CXF:

http://git-wip-us.apache.org/repos/asf/cxf/commit/7d866415

Thanks, SErgey
On 11/05/17 08:03, Rémi AUBEL wrote:

> Hi Sergey,
>
> For information, I have created issue  CXF-7367
> <https://issues.apache.org/jira/browse/CXF-7367>  .
>
> Thanks for your time,
> Rémi.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780373.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Rémi AUBEL
Hi Sergey,

It's strange. For now, I will use pre-matching filters only.
When I have more time, I will investigate more.

Thanks again.
Rémi.
Reply | Threaded
Open this post in threaded view
|

Re: ContainerRequestFilter not triggered on subresource

Sergey Beryozkin
Administrator
Hi Rémi

Sure, re-open CXF-7367 if you can indeed find the issue with the CXF
code. I think this specific scenario has been TCK tested - though it is
possible the TCK coverage has not been great. The easiest way would be
to debug as I suggested earlier.

Note if you subresource method contains a @NameBinding based annotation
then the filter will need to have it too.

Cheers, Sergey



On 12/05/17 09:15, Rémi AUBEL wrote:

> Hi Sergey,
>
> It's strange. For now, I will use pre-matching filters only.
> When I have more time, I will investigate more.
>
> Thanks again.
> Rémi.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ContainerRequestFilter-not-triggered-on-subresource-tp5780240p5780423.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>