users@jersey.java.net

[Jersey] Re: Reg : Inject Class Field into ResourceMethodDispatchProvider

From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Wed, 17 Jul 2013 14:01:06 +0200

Hi Barada,

ResourceMethodDispatchProvider are invoked during JAX-RS application
creation (i.e. deployment time) and you have no security context
available at this time. You can, of course, inject the SecurityContext
(it will be a proxy) into your ResourceMethodDispatchProvider
implementation (via @Context) but you can't use it sooner than in a
RequestDispatcher instance you're creating and returning from the
ResourceMethodDispatchProvider#create method:

public class MyDispatchProvider implements ResourceMethodDispatchProvider {

     @Context
     private SecurityContext securityContext;

     @Override
     public RequestDispatcher create(AbstractResourceMethod
abstractResourceMethod) {
         return new RequestDispatcher() {
             @Override
             public void dispatch(final Object resource, final
HttpContext context) {
                 // Here you can use the SecurityContext.
                 // if (securityContext.isSecure()) {
                 // ...
                 // }
             }
         };
     }
}

Michal

On 17.07.2013 08:56 , Barada (Personal) wrote:
> Hi,
>
> Am using Jersey 1.17.
> Am using a custom ResourceMethodDispatchProvider to decorate a resource method.
>
> Does Jersey provide any method of doing a class field injection (by using an InjectableProvider) into a custom ResourceMethodDispatchProvider?
>
> Am attempting to use the SecurityContext under which the request is executed.
>
> ~ Barada
> @baradasahu
>
>
>
>