I want to always have access to the current user domain instance in grails. I am currently using spring security. How do I go about adding current user to the context for all GSP pages? I was using request.user but thats not always populated.
For instance I want to be able to always access
${_currentUser.messages}
I know about the UserDetails service, but that is for static data. I am going to be accessing things that could be changing.
Spring Security have a service class to get the current user. You can use this in a
TagLib
. For example:Use filters, add to grails-app/conf:
Then you will be able to retrieve it in all view/controllers. In views they will be accessible either through params or through model if model was defined in controller(any model) and in controllers it will be accessed through params object.
But be aware as it will be applied to images also. So use docs to apply filters to what you need http://grails.org/doc/2.2.1/ref/Plug-ins/filters.html