Skip to content

[AAD] Allow anonymous access to the client credentials sample API - #868

Draft
Moary Chen (moarychan) wants to merge 3 commits into
mainfrom
moarychan/docs-aad-resource-server-authentication
Draft

Moary Chen (moarychan) wants to merge 3 commits into
mainfrom
moarychan/docs-aad-resource-server-authentication

Conversation

@moarychan

@moarychan Moary Chen (moarychan) commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Make /webapiB/clientCredential explicitly accessible without a token in the Microsoft Entra ID Resource Server sample, following Azure/azure-sdk-for-java#51207.

The endpoint is intentionally public, not merely exempt from method-level scope or app-role checks. Its access policy should be expressed explicitly rather than depend on the SDK's previous missing default authorization rule.

Changes

  • Add a sample-owned SecurityFilterChain that retains the AAD resource server configurer, permits /webapiB/clientCredential, and requires authentication for all other requests.
  • Enable method security so the existing @PreAuthorize scope checks on /webapiB and /user remain effective.
  • Add eight focused Spring MVC integration test cases using synthetic configuration and a mocked JwtDecoder; no real credentials or Entra connection are needed.
  • Restore the README to the PR base, removing the previous documentation-only approach. There is no net README change.
  • Keep /api/hello, the mixed Web/API sample, OBO, and Web application code unchanged.

No SDK version bump or shared SDK configurer change is required to express this sample-specific policy. The tests pass with the currently pinned Spring Cloud Azure 7.4.0.

Does this introduce a breaking change?

  • Yes
  • No

The public sample endpoint remains callable anonymously, while the other existing REST endpoints retain their authentication and scope requirements.

Pull Request Type

  • Bugfix
  • Feature
  • Code style update
  • Refactoring
  • Documentation content changes
  • Other

How to Test

From the aad-resource-server module:

mvn -B -ntp -Dtest=AadResourceServerConfigTests test

Completed locally:

  • Java 17 compilation and all eight test cases passed: zero failures, errors, or skipped tests.
  • Temporarily removing only the explicit permitAll() rule makes anonymousClientCredentialIsAllowed fail precisely with Status expected:<200> but was:<401>.
  • Restoring the rule and rerunning the complete test class passes all eight cases.
  • git diff --check passed.

What to Check

Request Expected result
Anonymous GET /webapiB/clientCredential 200 with the sample response
Anonymous GET /webapiB, /user, or another non-public path 401
Authenticated /webapiB or /user with the required scope 200
Authenticated /webapiB or /user without the required scope 403

The mocked decoder tests request authorization and the existing method permissions, not JWT signature verification.

Other Information

This update supersedes the earlier documentation-only draft. It does not move a catch-all authorization rule into the shared AAD configurer, change app-role policy, or modify other samples.

Clarify token authentication versus method-level permissions and document anonymous and client-credentials checks. Gate the checks on a release containing Azure/azure-sdk-for-java#51207.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Configure an explicit public endpoint with an authenticated fallback and retain method-level scope checks. Add focused MVC tests and restore the previous README content. Related to Azure/azure-sdk-for-java#51207.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moarychan Moary Chen (moarychan) changed the title [AAD] Clarify default resource server authentication [AAD] Allow anonymous access to the client credentials sample API Nov 13, 2026
@moarychan
Moary Chen (moarychan) marked this pull request as ready for review November 27, 2026 07:07
@moarychan
Moary Chen (moarychan) requested a review from a team as a code owner November 27, 2026 07:07
Copilot AI balanced review requested due to automatic review settings November 27, 2026 07:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the endpoint authorization change.

No open issues 🎉

What changed in this PR

This PR makes anonymous access to /webapiB/clientCredential explicit in the Microsoft Entra ID Resource Server sample while preserving authentication and scope checks for other endpoints.

Changes:

  • Adds a sample-owned security filter chain that retains the AAD configurer, permits the public endpoint, and requires authentication elsewhere.
  • Enables method security to preserve existing @PreAuthorize scope checks.
  • Adds eight integration test cases using synthetic configuration and a mocked JWT decoder, plus the required test dependency.
File Description
aad/​spring-cloud-azure-starter-active-directory/​web-client-access-resource-server/​aad-resource-server/​src/​test/​java/​com/​azure/​spring/​sample/​aad/​security/​AadResourceServerConfigTests.java Tests anonymous access, authentication requirements, and scope enforcement.
aad/​spring-cloud-azure-starter-active-directory/​web-client-access-resource-server/​aad-resource-server/​src/​main/​java/​com/​azure/​spring/​sample/​aad/​security/​AadResourceServerConfig.java Defines explicit request authorization and enables method security.
aad/​spring-cloud-azure-starter-active-directory/​web-client-access-resource-server/​aad-resource-server/​pom.xml Adds the Spring MVC test starter as a test-scoped dependency.

Review effort: Balanced

@moarychan

Copy link
Copy Markdown
Contributor Author

Copilot merge main branch to sync code

…source-server-authentication

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Copilot merge main branch to sync code

Merged main into the branch in merge commit 8275dc9; the focused AAD resource server tests pass (8/8).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants