I'm relatively new to Spring, and trying to queue up a set of web reqeusts on the server (in order to warm memcached). It's unclear to me how I can transfer on the current request's credentials to be used in the future web request I'm putting in the queue. I've seen a handful of scheduling solutions (TaskExecutor, ApplicationEventMultitasker, etc) but was unclear if/how they handle credentials, as that seems to be the most complicated portion of this task.
Asked
Active
Viewed 361 times
1
-
Starting to think executing the models I need instead of invoking a web request might be the most straight-forward approach, but still curious to hear about a web request queue that handles credentials. – Jeremy Mullin May 21 '12 at 16:25
1 Answers
0
It's not possible directly. Security credentials are stored in ThreadLocal
which means once the request is forwarded to another thread, credentials are lost. All you can do (which might actually be beneficial to your design) is to pass credentials directly, by wrapping them inside Callable
/Runnable
or whatever mechanism you use.

Tomasz Nurkiewicz
- 334,321
- 69
- 703
- 674
-
1You could set the security creds on the `ThreadLocal` using a wrapping aspect, and then unset at the end after the method call (`@Around`). However, you would need to make really sure the creds are unset, even in error scenarios. I would probably put the creds under some non-standard handle so that no other processing picks up on them other than the code which actually uses them. – atrain May 21 '12 at 18:52