spring-projects / spring-projects/spring-security
the securityContext will be lost in jsp page when use the spring async controller.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Summary
spring security: 4.1.2.RELEASE
the securityContext will be lost in jsp page when use the spring async controller with callable dispatcher result, and the authorize tag will not work.
Actual Behavior
-
in a spring controller method, return a Callable type to dispatch to a jsp page.
`
public Callable list() {return () -> { //doSomething return "jsppage"; };}
` -
in jsppage, use the authorize tag
< security:authorize access="hasAuthority('code')" > test < /security:authorize >
the 'test' will not be show although I login with a user which has the 'code' authority. -
in fact, the below code in the AbstractAuthorizeTag#authorizeUsingAccessExpression that want to obtain the authentication will return null.
if (SecurityContextHolder.getContext().getAuthentication() == null) { return false; } -
The reason of this issue is the page dispatch and render in difference thread that managed by container which without set securityContext.
Expected Behavior
when I use async controller, the jsp tag authorize should be work correctly.
Configuration
Version
spring security: 4.1.2.RELEASE
tomcat: 8.0.30
Sample
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Callable controller flow with the JSP authorize tag described in the issue, then read AbstractAuthorizeTag#authorizeUsingAccessExpression and the async dispatch path. Confirm that authentication is unavailable during JSP rendering; done means the authorize tag works correctly for an authenticated user with the required authority.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100