Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get web session on Spring AOP

I have a question for using Spring AspectJ. I want to create an audit log when the user does something and get user information from web session to create the audit log. Can anyone provide examples of how to do this?

like image 346
MewZ Avatar asked Sep 29 '10 16:09

MewZ


1 Answers

Spring MVC's DispatcherServlet stores request in a thread-local variable (if you don't use Spring MVC, you may declare RequestContextListener in web.xml to do the same thing). This variable can be accessed via RequestContextHolder:

HttpSession s = (HttpSession) RequestContextHolder
                    .currentRequestAttributes()
                    .resolveReference(RequestAttributes.REFERENCE_SESSION);
like image 64
axtavt Avatar answered Sep 22 '22 18:09

axtavt