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
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() {
}
`
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