users@jersey.java.net

Using a filter for Basic Authentication and handling different paths

From: Kevin Duffey <andjarnic_at_yahoo.com>
Date: Thu, 20 Nov 2008 22:40:56 -0800 (PST)

Hi all,

I hope I am not duplicating a post from earlier.. looked back a bit and can't find much on filters and nothing that I read seems to satisfy my issue at hand.

I have implemented ContainerRequestFilter, and want to use this to authenticate all calls. I am curious if @PathParam, @HeaderParam, and such work still. I can't seem to find any good info on whether or not the annotations work with these interfaces or only after they've passed the request on. For the most part I believe I can use this filter to authenticate all requests. I do have an issue tho where the specific url path provides a user id that I must use to match against the authentication credentials. In my Resource classes I have something like @Path("/users") and a sub-resource method in that class with @Path("{userid}/anotherpath")... and the subresource uses the @PathParam to get the userid. Presently, I actually authenticate in every single method call.. and in this particular case I need that passed in userid on the URI path to match against the Authorization header credentials. I am wondering if there is any way to pull this info out inside the
 filter without having to dissect the path URI myself?

Worse case scenario I would just do a sort of double authentication.. where the filter confirms that Authorization header credentials is valid.. then in the specific sub-resource method, get the path param and and do that check there.

Thanks.