Class McpAudienceValidator
java.lang.Object
org.apache.juneau.rest.server.mcp.v20260728.McpAudienceValidator
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.JwtTokenValidatorenforcingaudinternally, or an introspection AS that legitimately omitsaud).
- Since:
- 10.0.0
-
Method Summary
-
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 benull (returnsfalse ).expectedAudience- The expected audience (this server's resource identifier). Must not benull or blank.requireAudienceClaim- Whether a principal exposing no claims is rejected (fail-closed) rather than passed (seeMcpResourceServerConfig.isRequireAudienceClaim()).- Returns:
true if the audience matches, or the principal exposes no claims andrequireAudienceClaimisfalse ;false if the principal isnull , exposes no claims whilerequireAudienceClaimistrue , or carries claims whoseaud/resourcedo not include the expected audience.
-