Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1112

ResourceMethodInvoker returns method declaring class instead of resource class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 3.0.9.Final
    • jaxrs
    • Low

      I have built a dynamic feature to manage authentication using Resource class annotation and/or method annotation.

      See example code below

      /**
       * Activate authentication on annotated JAX-RS resource methods
       */
      @Provider
      public class AuthenticationFeature implements DynamicFeature {
      
        @Override
        public void configure(ResourceInfo resourceInfo, FeatureContext context) {
          Method method = resourceInfo.getResourceMethod();
          Class<?> clazz = resourceInfo.getResourceClass();
          if (!method.isAnnotationPresent(PermitAll.class)&&!clazz.isAnnotationPresent(PermitAll.class)) {
            AuthenticationFilter authenticationFilter =
                new AuthenticationFilter();
            context.register(authenticationFilter);
          }
        }
      
      }
      

      I have defined a custom resource that inherit from Swagger ApiListingResource to permit access to everyone :

      @Path("/api/docs/swagger")
      @Api("/api/docs/swagger")
      @Produces(MediaType.APPLICATION_JSON)
      @PermitAll
      public class SwaggerApiListingResource extends ApiListingResource {
      }
      

      But the dynamic feature fails because resourceClass() returns method.declaringClass() instead of resource.getClass() :

      public ResourceMethodInvoker(ResourceMethod method, InjectorFactory injector, ResourceFactory resource, ResteasyProviderFactory providerFactory)
         {
            this.injector = injector;
            this.resource = resource;
            this.parentProviderFactory = providerFactory;
            this.method = method;
            this.methodAnnotations = this.method.getAnnotatedMethod().getAnnotations();
      
             resourceInfo = new ResourceInfo()
            {
               @Override
               public Method getResourceMethod()
               {
                  return ResourceMethodInvoker.this.method.getAnnotatedMethod();
               }
      
               @Override
               public Class<?> getResourceClass()
               {
                  return ResourceMethodInvoker.this.method.getResourceClass().getClazz();
               }
            };
      ...
      

              rsigal@redhat.com Ronald Sigal
              matrousse Mathieu Rousselle (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Estimated:
                  Original Estimate - 10 minutes
                  10m
                  Remaining:
                  Remaining Estimate - 10 minutes
                  10m
                  Logged:
                  Time Spent - Not Specified
                  Not Specified