Skip to content

the securityContext will be lost in jsp page when use the spring async controller. #4047

@wayshall

Description

@wayshall

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

  1. in a spring controller method, return a Callable type to dispatch to a jsp page.
    `
    public Callable list() {

    return () -> {
        //doSomething
        return "jsppage";
    };
    

    }
    `

  2. 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.

  3. 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; }

  4. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions