0

i would like to get a session attribute (user name) in order to inject it into a MDC for a logger.

I don't even know if it is possible.

Any idea ? thanks


[ Edit ]

We are working with an Ajax framework (Zk). So the solution with Filter is not applicable. We have to put and remove in each event triggered by the framework in order to write into specific log (by user).

So i search how to automate these action with AOP.

MychaL
  • 969
  • 4
  • 19
  • 37
  • Have you looked at these answers? http://stackoverflow.com/questions/6115858/logging-user-activity-in-web-app http://stackoverflow.com/questions/248562/when-using-spring-security-what-is-the-proper-way-to-obtain-current-username-i – Chris H Jul 29 '13 at 17:16
  • I have edited my request. Filter is not a solution for us, unfortunatly. – MychaL Jul 30 '13 at 16:10

1 Answers1

0

From one of the spring forums discussion:

I would implement this with a ServletFilter, this way you have access to all the stuff in the request and session. Use the DelegatingFilterProxy so that you can configure your Filter as a normal Spring bean.

If you really need to or want to implement it as an Aspect I would also suggest that you define a filter. That filter will put the desired parameter in a ThreadLocal, that way you can retrieve the proper value from inside the Aspect.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136