Class McpAudienceValidator

java.lang.Object
org.apache.juneau.rest.server.mcp.v20260728.McpAudienceValidator

public final class McpAudienceValidator extends Object
RFC 8707 audience enforcement — the confused-deputy defense pairing with the MCP client's resource indicator.

Confirms that a validated access token was actually minted for this resource by checking that the token's aud or resource claim contains this server's resource identifier, rejecting a token whose audience targets a different resource.

Claims requirement:

Gate-level enforcement applies to a ClaimsPrincipal (as produced by JwtTokenValidator and OAuth introspection). A validator returning a bare Principal that exposes no claims cannot be checked at the gate; the requireAudienceClaim flag decides the disposition:

  • true (the default) — fail-closed: a claims-less principal is rejected, so the confused-deputy defense is never silently a no-op.
  • false — opt-out: a claims-less principal passes, delegating audience enforcement to the validator itself (e.g. JwtTokenValidator enforcing aud internally, or an introspection AS that legitimately omits aud).
Since:
10.0.0
  • Method Details

    • matches

      public static boolean matches(Principal principal, String expectedAudience, boolean requireAudienceClaim)
      Returns whether the principal's token audience matches the expected resource identifier.
      Parameters:
      principal - The authenticated principal. May be null (returns false).
      expectedAudience - The expected audience (this server's resource identifier). Must not be null or blank.
      requireAudienceClaim - Whether a principal exposing no claims is rejected (fail-closed) rather than passed (see McpResourceServerConfig.isRequireAudienceClaim()).
      Returns:
      true if the audience matches, or the principal exposes no claims and requireAudienceClaim is false; false if the principal is null, exposes no claims while requireAudienceClaim is true, or carries claims whose aud/resource do not include the expected audience.