@Test public void checkEndpointAuthorizationFilterRegistrationForSecuredMethod() throws Exception { ResourceInfo resourceInfo = mock(ResourceInfo.class); when(resourceInfo.getResourceMethod()).thenReturn(AuthorizationFilterTest.class.getMethod("MySecuredMethod")); when(resourceInfo.getResourceClass()).thenReturn((Class) AuthorizationFilterTest.class); FeatureContext context = mock(FeatureContext.class); AuthorizationFilter instance = new AuthorizationFilter(); instance.configure(resourceInfo, context); ArgumentCaptor<EndpointPermissionAuthorizationFilter> endpointAuthorizationFilterArgumentCaptor = ArgumentCaptor.forClass(EndpointPermissionAuthorizationFilter.class); ArgumentCaptor<EndpointPersonalCertificateAuthorizationFilter> endpointPersonalCertificateAuthorizationFilterArgumentCaptor = ArgumentCaptor.forClass(EndpointPersonalCertificateAuthorizationFilter.class); ArgumentCaptor<EndpointAdminOnlyAuthorizationFilter> endpointAdminOnlyAuthorizationFilterArgumentCaptor = ArgumentCaptor.forClass(EndpointAdminOnlyAuthorizationFilter.class); verify(context) .register(endpointAdminOnlyAuthorizationFilterArgumentCaptor.capture(), eq(Priorities.AUTHORIZATION + 10)); verify(context) .register(endpointAuthorizationFilterArgumentCaptor.capture(), eq(Priorities.AUTHORIZATION + 20)); verify(context).register(endpointPersonalCertificateAuthorizationFilterArgumentCaptor.capture(), eq(Priorities.AUTHORIZATION + 30)); verifyNoMoreInteractions(context); Assert.assertEquals(MY_PERMISSION, endpointAuthorizationFilterArgumentCaptor.getValue().getPermission()); Assert.assertEquals(MY_PERMISSION, endpointPersonalCertificateAuthorizationFilterArgumentCaptor.getValue().getPermission()); }
@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);  }