Get current CMS user on Groovy updater scripts


I am using the version 12.6.25 off Bloomreach Experience Manager.

Each time I do an update on a document using an Groovy updater script I want to update the value of the field hippostdpubwf:lastModifiedBy with the user name that is currently logged into the CMS and executes the script.

If I retrieve the value of the user from the session with the bellow example, it always returns the values system, with any user that is logged into the CMS:

Is there any way to retrieve the value of the actual user that connect to the CMS (not system) on the Groovy updater scripts?

Right off the top of my head I don’t think so. The updater runs in a somewhat protected environment. You could consider adding the user as an unput parameter, but that would be manual input which is error prone. I won’t say with certainty that it isn’t possible, but I can’t immediately think of a way.

You can try static org.hippoecm.frontend.session.UserSession.get().getJcrSession(), but not completely sure if the static #get() returns something in Groovy.

@jeroen.hoffman I’ve tried your approach but it does not work on the editor scripts. When I try to retrieve the user with org.hippoecm.frontend.session.UserSession.get().getJcrSession() I get the bellow error:

org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-5-thread-1

UserSession.get().getJcrSession() uses threadlocals I believe and is tied to user request. Groovy scripts are run as a background task and run by “system” user
(in most cases are not even triggered by a user, but scheduled or bootstrapped into registry).