AuthorizationFeature implements DynamicFeature { @Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { Method method = resourceInfo.getResourceMethod(); SecurityHole securityHole = annotationLocator.getAnnotation(method, SecurityHole.class); String name = method.getDeclaringClass().getName() + "." + method.getName(); if (securityHole != null) { log.debug("Not registering authorization filter on {}", name); context.register(securityHoleFilter); } else if (resourceInfo.getResourceClass().equals(ApiListingResource.class)) { log.debug("Not registering authorization filter for Swagger: {}", name); context.register(securityHoleFilter); } else if (isSuperAdminOnly(method)) { log.debug("Registering superadmin only on {}", name); context.register(superAdminFilter); } else { log.debug("Registering standard authorization on {}", name); context.register(authorizationFilter); } } @Inject  AuthorizationFeature(VerifyAuthorizationFilter authorizationFilter,
        SuperAdminAuthorizationFilter superAdminFilter,
        SecurityHoleAuthorizationFilter securityHoleFilter,
        AnnotationLocator annotationLocator); @Override void configure(ResourceInfo resourceInfo, FeatureContext context);  }
@Test public void testConfigureWithSecurityHole() throws Exception { Method m = FakeResource.class.getMethod("methodWithSecurityHole", String.class); when(resourceInfo.getResourceMethod()).thenReturn(m); authorizationFeature.configure(resourceInfo, context); verify(context).register(eq(securityHoleFilter)); }
@Test public void testConfigureWithSuperAdminMethod() throws Exception { Method m = FakeResource.class.getMethod("superAdminOnlyMethod", String.class); when(resourceInfo.getResourceMethod()).thenReturn(m); authorizationFeature.configure(resourceInfo, context); verify(context).register(eq(superAdminFilter)); }
@Test public void testConfigureWithVerifyAnnotation() throws Exception { Method m = FakeResource.class.getMethod("methodWithVerify", String.class); when(resourceInfo.getResourceMethod()).thenReturn(m); authorizationFeature.configure(resourceInfo, context); verify(context).register(eq(verifyFilter)); }
@Test public void testConfigureSpecFirstWithSecurityHole() throws Exception { Method m = FakeApi.class.getMethod("methodWithSecurityHole", String.class); when(resourceInfo.getResourceMethod()).thenReturn(m); authorizationFeature.configure(resourceInfo, context); verify(context).register(eq(securityHoleFilter)); }
@Test public void testConfigureSpecFirstWithSuperAdminMethod() throws Exception { Method m = FakeApi.class.getMethod("superAdminOnlyMethod", String.class); when(resourceInfo.getResourceMethod()).thenReturn(m); authorizationFeature.configure(resourceInfo, context); verify(context).register(eq(superAdminFilter)); }
@Test public void testConfigureSpecFirstWithVerifyAnnotation() throws Exception { Method m = FakeApi.class.getMethod("methodWithVerify", String.class); when(resourceInfo.getResourceMethod()).thenReturn(m); authorizationFeature.configure(resourceInfo, context); verify(context).register(eq(verifyFilter)); }