@Test public void checkNoEndpointAuthorizationFilterRegistrationForUnsecuredMethod() throws Exception { ResourceInfo resourceInfo = mock(ResourceInfo.class); when(resourceInfo.getResourceMethod()).thenReturn(this.getClass().getMethod("MyUnsecuredMethod")); when(resourceInfo.getResourceClass()).thenReturn((Class) AuthorizationFilterTest.class); FeatureContext context = mock(FeatureContext.class); AuthorizationFilter instance = new AuthorizationFilter(); instance.configure(resourceInfo, context); verify(context, never()).register(any(), anyInt()); }
@Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { Secured securedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Secured.class); if (securedAnnotation == null) { LOGGER.debug(String.format("Ignoring Non-@%s annotated method %s.%s", Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); return; } LOGGER .debug(String.format("Registering authorization filters with '%s' permission for %s annotated method %s.%s", securedAnnotation.permission(), Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); context.register(new EndpointAdminOnlyAuthorizationFilter(securedAnnotation.isAdminOnly()), Priorities.AUTHORIZATION + 10); context.register(new EndpointPermissionAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 20); context.register(new EndpointPersonalCertificateAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 30); }
AuthorizationFilter implements DynamicFeature { @Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { Secured securedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Secured.class); if (securedAnnotation == null) { LOGGER.debug(String.format("Ignoring Non-@%s annotated method %s.%s", Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); return; } LOGGER .debug(String.format("Registering authorization filters with '%s' permission for %s annotated method %s.%s", securedAnnotation.permission(), Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); context.register(new EndpointAdminOnlyAuthorizationFilter(securedAnnotation.isAdminOnly()), Priorities.AUTHORIZATION + 10); context.register(new EndpointPermissionAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 20); context.register(new EndpointPersonalCertificateAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 30); } }
AuthorizationFilter implements DynamicFeature { @Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { Secured securedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Secured.class); if (securedAnnotation == null) { LOGGER.debug(String.format("Ignoring Non-@%s annotated method %s.%s", Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); return; } LOGGER .debug(String.format("Registering authorization filters with '%s' permission for %s annotated method %s.%s", securedAnnotation.permission(), Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); context.register(new EndpointAdminOnlyAuthorizationFilter(securedAnnotation.isAdminOnly()), Priorities.AUTHORIZATION + 10); context.register(new EndpointPermissionAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 20); context.register(new EndpointPersonalCertificateAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 30); }  }
AuthorizationFilter implements DynamicFeature { @Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { Secured securedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Secured.class); if (securedAnnotation == null) { LOGGER.debug(String.format("Ignoring Non-@%s annotated method %s.%s", Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); return; } LOGGER .debug(String.format("Registering authorization filters with '%s' permission for %s annotated method %s.%s", securedAnnotation.permission(), Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); context.register(new EndpointAdminOnlyAuthorizationFilter(securedAnnotation.isAdminOnly()), Priorities.AUTHORIZATION + 10); context.register(new EndpointPermissionAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 20); context.register(new EndpointPersonalCertificateAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 30); }  @Override void configure(ResourceInfo resourceInfo, FeatureContext context); }
AuthorizationFilter implements DynamicFeature { @Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { Secured securedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Secured.class); if (securedAnnotation == null) { LOGGER.debug(String.format("Ignoring Non-@%s annotated method %s.%s", Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); return; } LOGGER .debug(String.format("Registering authorization filters with '%s' permission for %s annotated method %s.%s", securedAnnotation.permission(), Secured.class.getName(), resourceInfo.getResourceClass().getName(), resourceInfo.getResourceMethod().getName())); context.register(new EndpointAdminOnlyAuthorizationFilter(securedAnnotation.isAdminOnly()), Priorities.AUTHORIZATION + 10); context.register(new EndpointPermissionAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 20); context.register(new EndpointPersonalCertificateAuthorizationFilter(securedAnnotation.permission()), Priorities.AUTHORIZATION + 30); }  @Override void configure(ResourceInfo resourceInfo, FeatureContext context);  }