2

I´m using Spring @Async for make an asynchronous request, but problem is that in order to do that request I need "authentication" of Spring security in my SecurityContextHolder.

In order to make it works what do you think is the best option to copy the session from one thread to other.

Nitin Arora
  • 2,650
  • 1
  • 26
  • 27
paul
  • 12,873
  • 23
  • 91
  • 153
  • It is answered here http://stackoverflow.com/questions/5246428/spring-security-and-async – Nitin Arora Apr 28 '15 at 07:50
  • What he is doing is what I´m doing right now. Pass the authentication to the async method to be set there. I even rather my approach. It´s more clean and no magic stuff. But the authentication was just one of the possible issues. I´m suffering problems with Hibernate session issues as well. – paul Apr 28 '15 at 08:09

1 Answers1

1

try to create empty SecurityContext from another thread, then set authentication to that context, then set this context to SecurityContextHolder as a newly created context. You can run it in runnable

erhanasikoglu
  • 1,685
  • 1
  • 21
  • 33
  • that´s what I´m doing, but I would like a nice mechanism to copy the whole bean session scope. – paul Apr 28 '15 at 09:06