5

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?

1 Answer 1

6

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.