@VisibleForTesting
  static void selectHandler(
      final RoutingContext context,
      final Pattern skipPathsPattern,
      final boolean jaasAvailable,
      final boolean pluginAvailable
  ) {
    if (skipPathsPattern.matcher(context.normalizedPath()).matches()) {
      context.data().put(PROVIDER_KEY, Provider.SKIP);
      context.next();
      return;
    }
    if (SystemAuthenticationHandler.isAuthenticatedAsSystemUser(context)) {
      context.data().put(PROVIDER_KEY, Provider.SYSTEM);
      context.next();
      return;
    }

    final String authHeader = context.request().getHeader("Authorization");
    if (jaasAvailable && authHeader != null && authHeader.toLowerCase().startsWith("basic ")) {
      context.data().put(PROVIDER_KEY, Provider.JAAS);
    } else if (pluginAvailable) {
      context.data().put(PROVIDER_KEY, Provider.PLUGIN);
    } else {
      // Fail the request as unauthorized - this will occur if no auth plugin but Jaas handler
      // is configured, but auth header is not basic auth
      context.fail(
          UNAUTHORIZED.code(),
          new KsqlApiException("Unauthorized", ERROR_CODE_UNAUTHORIZED));
    }
    context.next();
  }
@Test
  public void shouldSelectSkipProviderForUnauthorizedPaths() {
    // Given:
    Mockito.when(routingContext.normalizedPath()).thenReturn("/unauthorized_path");
    Map<String, Object> data = mock(Map.class);
    Mockito.when(routingContext.data()).thenReturn(data);
    Pattern p = Pattern.compile("/unauthorized.*");

    // When:
    AuthHandlers.selectHandler(routingContext, p, false, true);

    // Then (make sure "skip" provider is selected):
    Mockito.verify(data).put("provider", AuthHandlers.Provider.SKIP);
    Mockito.verify(routingContext).next();
  }