-
Bug
-
Resolution: Won't Do
-
Major
-
None
-
3.0.9.Final
-
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(); } }; ...