Reputation: 1153
From what I can tell, the spring security filterchain runs twice per request for @Async requests, because it runs on the inbound request thread, is passed to the async code which runs on a different thread, and then when it attempts to write to the response thread the security filterchain runs again. I believe this is due to the use of a ThreadLocal for storing the security context.
I am able to successfully pass the security context into the asynchronous code, the issue is whenever I attempt to write the response the filterchain runs again.
I am encountering a similar situation as described here:
Is this simply expected behavior that we should account for when using spring security, or is there a configuration I am missing that would prevent the second execution of the filterchain?
Upvotes: 2
Views: 1811
Reputation: 87
Set property spring.security.filter.dispatcher-types=REQUEST,ERROR
. Spring will not apply filters for call dispatched from async context.
Upvotes: 0
Reputation: 1153
got an answer here: https://github.com/spring-projects/spring-security-oauth/issues/736
apparently the fix is to configure security.filter-dispatcher-types=REQUEST, ERROR
Upvotes: 1