Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Log Effective Authorization Rules - #20194

Draft
fhrmrk wants to merge 2 commits into
spring-projects:mainfrom
fhrmrk:gh-20174
Draft

fhrmrk wants to merge 2 commits into
spring-projects:mainfrom
fhrmrk:gh-20174

Conversation

@fhrmrk

@fhrmrk fhrmrk commented Dec 1, 2026

Copy link
Copy Markdown

This addresses the first item of gh-20174, "Log the effective authorization rules".

When a DefaultSecurityFilterChain is created, it now emits one additional debug event that pairs the chain's request matcher with the rules of its AuthorizationFilter:

Will authorize PathPattern [/api/**] with RequestMatcherDelegatingAuthorizationManager[mappings=[PathPattern [GET /api/public/**] -> SingleResultAuthorizationManager[granted=true], PathPattern [/api/admin/**] -> AuthorityAuthorizationManager[authorities=[ROLE_ADMIN]], any request -> AuthenticatedAuthorizationManager[authenticated]]]

To make that readable, this PR also adds toString() to the managers the DSL produces that did not have one:

  • SingleResultAuthorizationManager
  • AuthenticatedAuthorizationManager
  • AllAuthoritiesAuthorizationManager
  • the managers returned by AuthorizationManagers#anyOf, #allOf, and #not
  • RequestMatcherDelegatingAuthorizationManager, which lists its mappings in evaluation order

The formats follow the existing AuthorityAuthorizationManager[authorities=...] convention.

Notes for review

  • I placed the log in DefaultSecurityFilterChain rather than HttpSecurity#performBuild (as I first suggested in the issue) because it already logs "Will secure ... with filters" there, it has both the matcher and the filters, and it needs no new public API. It also covers chains that are not built through HttpSecurity.
  • The level is DEBUG and the rules are on a single line. I'm happy to change the level, the placement, or the format, or to split the toString() additions into a separate PR.
  • When the manager is wrapped (for example by ObservationAuthorizationManager), the rules are not visible yet. I left that out to keep this change small.
  • The other two items in the issue (per-decision trace and gotcha detection) are not part of this PR.

Issue gh-20174

SingleResultAuthorizationManager, AuthenticatedAuthorizationManager,
AllAuthoritiesAuthorizationManager, and the managers returned by
AuthorizationManagers#anyOf, #allOf, and #not now describe
themselves so that authorization rules are readable in logs.

Issue spring-projectsgh-20174

Signed-off-by: 박종현 <fhrmrk@naver.com>
When a DefaultSecurityFilterChain is created, log the chain's
request matcher together with the rules of its AuthorizationFilter
in a single debug event.

RequestMatcherDelegatingAuthorizationManager#toString now lists
each request matcher and its AuthorizationManager in the order
they are evaluated.

Issue spring-projectsgh-20174

Signed-off-by: 박종현 <fhrmrk@naver.com>

This branch has not been deployed

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

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants