Event Listener Not Working Without Administrative Session | Community
Skip to main content
Tuhin_Ghosh
Level 8
June 15, 2017
Solved

Event Listener Not Working Without Administrative Session

  • June 15, 2017
  • 17 replies
  • 6864 views

Hello Everyone,

I am writing an EventListener but the onEvent() method is not getting called if I create the session by doing below:

Map<String, Object> param = new HashMap<>()
param.put(ResourceResolverFactory.SUBSERVICE, "SUBSERVICENAME")
resourceResolver = resourceResolverFactory.getServiceResourceResolver(param)
session = resourceResolver.adaptTo(Session.class)

however if I am creating the session by "repository.loginAdministrative(null)" the class is working as expected and the onEvent() is getting called. The latest example in the ACS Commons github is also getting the session by "repository.loginAdministrative(null)".
https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/adobe/acs/samples/events/impl/SampleJcrEventListener.java

But it is not advisable to use repository.loginAdministrative(null) to obtain the session, not to mention its also deprecated. I was just wondering if anyone have faced this before and have some possible solution.

Thanks and Regards,

Tuhin

P.S: My service user have all the permission it needs to do any kind of operation on node.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

This looks like a bug. I would file a ticket to let the team know this is not working. LOoks like you are doing everything you are suppose to do.

17 replies

Rajeev_Kumar
Level 3
June 15, 2017

Did you configure the user id in Apache User Mapper Service ?

Also, debug the code and see if you are getting the resource resolver.

Tuhin_Ghosh
Level 8
June 15, 2017

Hi Rajeev,

The user is all good. Working fine for other classes. I am also getting the resource resolver. There isn't any error in the logs too.

thanks

smacdonald2008
Level 10
June 15, 2017

Did you try and put the System user in an admin group - did that work?

Rajeev_Kumar
Level 3
June 15, 2017

Did you check if your eventListener class is active when you are using System user to get session. Also, check error log if there is any error.
And if possible, use sling eventHandler instead of eventListener as mentioned at https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/j ava/com/adobe/acs/samples/events/impl/SampleJcrEventListener.java

joerghoh
Adobe Employee
Adobe Employee
June 15, 2017

Hi,

is your user capable to read the content areas, where the user is supposed to have read access to, and all nodes up to the root node? I've never faced your problem, but I could imagine, that internally some traversal is done, which requires these additional permissions.

kind regards,
Jörg

Tuhin_Ghosh
Level 8
June 15, 2017

Hi Scott,

I have tried the same. It didn't work.

Regards,

Tuhin

Tuhin_Ghosh
Level 8
June 15, 2017

@Rajeev, I have tried everything, then only I have posted this question. The class is fine and active in OSGI, activate method working fine while activating the service. The URL you have mentioned is also mentioned in my question itself.

I know about Sling Event Handler, and that is an alternative. But why should a code is not working which is supposed to work that is my question.

Tuhin_Ghosh
Level 8
June 15, 2017

Hi Jörg Hoh

I have added all permissions just to make sure that its not the permission issue specific to my user. But no luck.

Regards,

Tuhin

smacdonald2008
smacdonald2008Accepted solution
Level 10
June 16, 2017

This looks like a bug. I would file a ticket to let the team know this is not working. LOoks like you are doing everything you are suppose to do.

smacdonald2008
Level 10
June 16, 2017

Also - what AEM version are you using?