Repository navigation
[AAD] Allow anonymous access to the client credentials sample API - #868
Draft
Moary Chen (moarychan) wants to merge 3 commits into
Draft
Moary Chen (moarychan) wants to merge 3 commits into
Moary Chen (moarychan) wants to merge 3 commits into
Conversation
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>
2 of 8 tasks
Moary Chen (moarychan)
marked this pull request as ready for review
November 27, 2026 07:07
There was a problem hiding this comment.
🟢 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
@PreAuthorizescope 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
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>
Contributor
Merged |
Moary Chen (moarychan)
marked this pull request as draft
November 27, 2026 07:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Make
/webapiB/clientCredentialexplicitly 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
SecurityFilterChainthat retains the AAD resource server configurer, permits/webapiB/clientCredential, and requires authentication for all other requests.@PreAuthorizescope checks on/webapiBand/userremain effective.JwtDecoder; no real credentials or Entra connection are needed./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?
The public sample endpoint remains callable anonymously, while the other existing REST endpoints retain their authentication and scope requirements.
Pull Request Type
How to Test
From the
aad-resource-servermodule:mvn -B -ntp -Dtest=AadResourceServerConfigTests testCompleted locally:
permitAll()rule makesanonymousClientCredentialIsAllowedfail precisely withStatus expected:<200> but was:<401>.git diff --checkpassed.What to Check
GET /webapiB/clientCredentialGET /webapiB,/user, or another non-public path/webapiBor/userwith the required scope/webapiBor/userwithout the required scopeThe 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.