Class ApiKeyServerInterceptor

java.lang.Object
ai.pipeline.connector.intake.grpc.ApiKeyServerInterceptor
All Implemented Interfaces:
io.grpc.ServerInterceptor

@ApplicationScoped public class ApiKeyServerInterceptor extends Object implements io.grpc.ServerInterceptor
Captures the x-api-key gRPC metadata header into the call Context.

This is the ONLY way credentials enter the intake gRPC surface — request messages carry no api_key fields (security audit 2026-06-12; the proto fields are reserved). Services read the key via apiKey() on the thread handling the call.

  • Field Details

    • API_KEY_HEADER

      public static final io.grpc.Metadata.Key<String> API_KEY_HEADER
      Header carrying the datasource API key.
  • Constructor Details

    • ApiKeyServerInterceptor

      public ApiKeyServerInterceptor()
      CDI.
  • Method Details

    • apiKey

      public static String apiKey()
      The calling request's API key, or "" when the header was absent. Valid on any thread carrying the call's gRPC Context (request handlers, stream observer callbacks, and the thread that opened a bidi stream).
      Returns:
      the api key from x-api-key, never null
    • callWithApiKey

      public static <T> T callWithApiKey(String apiKey, Callable<T> body) throws Exception
      Run body with apiKey bound as the call credential. For in-process callers that bypass the gRPC server (tests injecting the service bean directly, internal replays) — over the wire the interceptor binds it from the x-api-key header instead.
      Type Parameters:
      T - the body's result type
      Parameters:
      apiKey - the api key to bind for the duration of body
      body - the work to run with the key bound
      Returns:
      body's result
      Throws:
      Exception - whatever body throws
    • interceptCall

      public <ReqT,RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT,RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT,RespT> next)
      Specified by:
      interceptCall in interface io.grpc.ServerInterceptor