Portlet : Trace logged user with MDC

Hi,

I’m using vaadin portlets applications (with Liferay portal) and i would like to :

  • add the current user in Spring context (SecurityContextHolder)
  • add the current user in logs files using SL4J (or LOG4J) and MDC

In order to do it, i added :

  • a portlet listener to my application
  • those actions at the begginning of handleRenderRequest, handleEventRequest and handleResourceRequest methods.

Here is my usecase :

  • I display my portlet (included in a Liferay page) in my browser, in guest mode ==> No user is logged in my logs files and no user is associated to the thread according in my SecurityContextHolder
  • I logged in Liferay
  • I display my portlet ==> The user is well printed in my logs files and the user is well associated in the SecurityContextHolder
  • I logged out and i display my portlet ==> the user is still in the logs files

MDC and SecurityContextHolder are supposed to be threadsafe. It seems that in portlet mode with vaadin (and maybe with other frameworks) it keeps the user in the thread even when the thread is over.

Does anybody know how to link the user to the thread ? Have you ever logged the portal user at the begining of a portlet request ?

I can explain or add further information if needed.