AuthenticationFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { log.debug("Authentication check for {}", requestContext.getUriInfo().getPath()); HttpRequest httpRequest = ResteasyContext.getContextData(HttpRequest.class); ResourceInfo resourceInfo = ResteasyContext.getContextData(ResourceInfo.class); Method method = resourceInfo.getResourceMethod(); SecurityHole hole = annotationLocator.getAnnotation(method, SecurityHole.class); Principal principal = null; if (hole != null && hole.anon()) { principal = new NoAuthPrincipal(); } else if (resourceInfo.getResourceClass().equals(ApiListingResource.class)) { log.debug("Swagger API request made; no principal required."); principal = new NoAuthPrincipal(); } else { for (AuthProvider provider : providers) { principal = provider.getPrincipal(httpRequest); if (principal != null) { log.debug("Establishing principal with {}", provider.getClass().getName()); break; } } } if (principal == null) { if (hole != null && hole.noAuth()) { log.debug("No auth allowed for resource; setting NoAuth principal"); principal = new NoAuthPrincipal(); } else if (!config.getBoolean(ConfigProperties.AUTH_OVER_HTTP) && !request.isSecure()) { throw new BadRequestException("Please use SSL when accessing protected resources"); } else { throw new NotAuthorizedException("Invalid credentials."); } } SecurityContext securityContext = new CandlepinSecurityContext(principal); requestContext.setSecurityContext(securityContext); ResteasyContext.pushContext(Principal.class, principal); } @Inject  AuthenticationFilter(Configuration config,
        ConsumerCurator consumerCurator,
        DeletedConsumerCurator deletedConsumerCurator,
        Injector injector,
        AnnotationLocator annotationLocator); void setHttpServletRequest(HttpServletRequest request); void setupAuthStrategies(); @Override void filter(ContainerRequestContext requestContext);  }
@Test public void keycloakAuthAuthentication() throws Exception { Method method = FakeResource.class.getMethod("someMethod", String.class); mockResourceMethod(method); mockReq.header("Authorization", "Bearer " + TESTTOKEN); keycloakSetup(); interceptor.filter(getContext()); Principal p = ResteasyContext.getContextData(Principal.class); assertEquals("qa@redhat.com", p.getName()); }