Hey
I have found some code that allow to use spring events
in async
way by overriding the code ApplicationEventMulticaster
, so each listener
will run its in own thread. example code here
My question is:
Does the security context will be the same as the publisher thread
? or i have to to pass user logged id
to each publisher
Thanks,
Oak
Edit:
Going through the docs:
i have found
Some applications aren't entirely suitable for using a ThreadLocal, because of the specific way they work with threads. For example, a Swing client might want all threads in a Java Virtual Machine to use the same security context. SecurityContextHolder can be configured with a strategy on startup to specify how you would like the context to be stored. For a standalone application you would use the SecurityContextHolder.MODE_GLOBAL strategy. Other applications might want to have threads spawned by the secure thread also assume the same security identity. This is achieved by using SecurityContextHolder.MODE_INHERITABLETHREADLOCAL. You can change the mode from the default SecurityContextHolder.MODE_THREADLOCAL in two ways. The first is to set a system property, the second is to call a static method on SecurityContextHolder. Most applications won't need to change from the default, but if you do, take a look at the JavaDocs for SecurityContextHolder to learn more.
So it seems that if one set up
SecurityContextHolder.MODE_INHERITABLETHREADLOCAL
is should work
My question is: does anyone have experience with this kind of configuration?