class JwtAuthFilter extends AuthFilter<Optional<String>, P> {

  @Override
  public void filter(ContainerRequestContext requestContext) {
    Span span =
        tracer
            .buildSpan("validateToken")
            .withTag(COMPONENT, "JwtAuthFilter")
            .withTag(AUTHENTICATED, false)
            .start();

    try (Scope ignored = tracer.scopeManager().activate(span)) {
      final MultivaluedMap<String, String> headers = requestContext.getHeaders();
      final String jwt = extractAuthorizationToken(headers);

      // validates the token and throws exception if invalid or expired
      boolean authenticated =
          authenticate(requestContext, Optional.ofNullable(jwt), SecurityContext.BASIC_AUTH);

      span.setTag(AUTHENTICATED, authenticated);

      if (!acceptAnonymous && !authenticated) {
        throw new JwtAuthException("Credentials are required to access this resource.");
      }
    } finally {
      span.finish();
    }
  }

  private  JwtAuthFilter();

}