Skip to content

Prefer dispatcher context for authorize tag beans#18822

Merged
jzheaux merged 2 commits intospring-projects:mainfrom
wonderfulrosemari:gh-8843-jsp-authorize-child-context
Mar 20, 2026
Merged

Prefer dispatcher context for authorize tag beans#18822
jzheaux merged 2 commits intospring-projects:mainfrom
wonderfulrosemari:gh-8843-jsp-authorize-child-context

Conversation

@wonderfulrosemari
Copy link
Copy Markdown
Contributor

Closes gh-8843

When both root and child web application contexts are present, JSP authorize
tags should resolve security beans from the DispatcherServlet context used for
the current request.

Previously, AbstractAuthorizeTag always resolved beans from
findRequiredWebApplicationContext(servletContext), which prefers the root
context. If security beans were defined only in the child context, this could
cause failures like missing WebSecurityExpressionHandler.

Changes include:

  • resolve application context from the current request's DispatcherServlet
    context attribute when available
  • fall back to SecurityWebApplicationContextUtils.findRequiredWebApplicationContext
    when no dispatcher context is present
  • add regression coverage for root+child context setup to ensure
    <sec:authorize> expression evaluation succeeds

Signed-off-by: wonderfulrosemari <whwlsgur1419@naver.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 28, 2026
Copy link
Copy Markdown
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

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

Thanks, @wonderfulrosemari, for the PR! I've left feedback inline.

@jzheaux jzheaux self-assigned this Mar 5, 2026
@jzheaux jzheaux added in: taglibs An issue in spring-security-taglibs type: enhancement A general enhancement status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 5, 2026
@jzheaux jzheaux removed the status: waiting-for-feedback We need additional information before we can continue label Mar 20, 2026
@jzheaux
Copy link
Copy Markdown
Contributor

jzheaux commented Mar 20, 2026

@wonderfulrosemari thank you again for the PR. I've applied the updates from my review; this PR will merge once the build completes.

@jzheaux jzheaux added this to the 7.1.0-RC1 milestone Mar 20, 2026
Closes spring-projectsgh-8843

Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
@jzheaux jzheaux force-pushed the gh-8843-jsp-authorize-child-context branch from d0b0ea1 to 830bba9 Compare March 20, 2026 22:32
@jzheaux jzheaux enabled auto-merge (rebase) March 20, 2026 22:32
@jzheaux jzheaux merged commit d76fb7f into spring-projects:main Mar 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: taglibs An issue in spring-security-taglibs type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JspAuthorizeTag cannot be used if spring-security configurations (beans) is not put in ROOT context (XML config).

3 participants