Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Current logged in user in event handler

Avatar

Level 2

I am having a event handler. It gets trigger when ever there is any change in node property.
Inside that event handler, how can I get which user changed the property. I want to get username / user id. Is there any way apart from lastmodified date of node
Thanks alot in advance

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

I don't think, that the jcr:lastModified and jcr:lastModifiedBy properties are updated on every change on a node. Otherwise every node should have these properties, and this isn't the case.

A sling resource event (which indicates a change to a resource) always logs the user, which has executed the changed. But with Oak this is true only for local changes, changes performed on a different cluster node have the user "oak:unknown". For this reason you should run this event listener on every cluster node and only check local changes.

kind regards,
Jörg

View solution in original post

7 Replies

Avatar

Level 10

If you are tracking on the Node property changed, the user who changed would be captured under jcr:content with the property cq:lastModifiedBy

Let me know if you are looking at something else

Avatar

Correct answer by
Employee Advisor

Hi,

I don't think, that the jcr:lastModified and jcr:lastModifiedBy properties are updated on every change on a node. Otherwise every node should have these properties, and this isn't the case.

A sling resource event (which indicates a change to a resource) always logs the user, which has executed the changed. But with Oak this is true only for local changes, changes performed on a different cluster node have the user "oak:unknown". For this reason you should run this event listener on every cluster node and only check local changes.

kind regards,
Jörg

Avatar

Level 2

Thanks for reponse @bsloki,

let say the node property name is 'mydata'.

Now when this property gets changes, two things will happen.

Task 1. cq:lastModifiedBy will get updated. ( Default AEM Behavior)

Task 2. My Event listener will get fired ( My Code)

Is there any possiblity that task 2 occur before task 1, which will give me old value not updated one in event listener. Whats your views in this case......

Avatar

Level 1

In Oak the user id in events is not guaranteed to be the actual user, events from other cluster nodes is just one scenario where that is true. The other known scenario is when too many events are being generated too fast, in which case multiple events get coalesced without respect for which user generated which event. AFAIK...

-Rob Ryan

Avatar

Level 10

In an JCR node event handler - the nodes are updated before the event handler is invoked.  That is, the handler listens for the node events. See: 

http://blogs.adobe.com/experiencedelivers/experience-management/event_handling_incq/

Avatar

Level 10

As @Scott mentioned, it shouldnt be the case as the actual action happens ie. update of a property along with which the lastModifiedBy will also be updated. Once that is saved successfully Event handler get triggered.

Avatar

Level 2

Thanks for answer and views guys, @scott, @bsloki