Class McpAuthInterceptor

java.lang.Object
org.apache.juneau.rest.client.mcp.McpAuthInterceptor
All Implemented Interfaces:
RestCallInterceptor

public class McpAuthInterceptor extends Object implements RestCallInterceptor
A builder-configurable auth-token seam implemented as a RestCallInterceptor.

On onInit(RestRequest), sets the Authorization request header to "Bearer " + token, where token comes from a caller-supplied Supplier. The OAuth/OIDC flows in juneau-rest-client-mcp-auth plug into this seam by supplying their own token-supplier implementation (e.g. one that refreshes an expired access token); this class implements no OAuth/OIDC flow itself.

If the supplied token is null or blank (empty or all-whitespace), no Authorization header is set for that request (the call proceeds unauthenticated) - a blank token is never sent as a credential-less Authorization: Bearer header. If the token supplier itself throws, RestRequest.run()'s documented interceptor-exception handling aborts the call before it is sent.

Note: when a token is set, enabling FINE/FINEST-level logging on the client's debug logger (see RestClient.Builder#debugLoggerName(String)) logs the full outgoing request including all headers, so enabling debug logging on a client using this interceptor will log the Authorization header (and therefore the bearer token) in plain text.

Since:
10.0.0
  • Constructor Details

    • McpAuthInterceptor

      public McpAuthInterceptor(Supplier<String> tokenSupplier)
      Constructor.
      Parameters:
      tokenSupplier - Supplies the bearer token for each request. Must not be null.
  • Method Details

    • ofStaticBearer

      public static McpAuthInterceptor ofStaticBearer(String token)
      Creates an interceptor that always sends the same static bearer token.
      Parameters:
      token - The static bearer token. Must not be null.
      Returns:
      A new interceptor. Never null.
    • onInit

      public void onInit(RestRequest req) throws Exception
      Description copied from interface: RestCallInterceptor
      Called before the transport request is built and sent.

      Use this hook to add headers, modify query parameters, or short-circuit the call.

      Specified by:
      onInit in interface RestCallInterceptor
      Parameters:
      req - The request being built. Never null.
      Throws:
      Exception - If the call should be aborted.