AEM 6.4 unable to access content path via resourceresolver/session | Community
Skip to main content
New Participant
May 17, 2018
Solved

AEM 6.4 unable to access content path via resourceresolver/session

  • May 17, 2018
  • 31 replies
  • 14156 views

Hey Guys,

I am trying to access the path under content structure and i see that the code keeps complaining that path under /content does not exist.

i have a system user with permissions to /content folder and i am trying to get the resourceresolver via the java code and check if the node exists at the path. The output is that the node does not exist for any path under /content. is there something i am missing? I see that session.nodeExists works if i test for path under apps.

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 NitroHazeDev

Hi,

I had to alter the code discussing with Adobe

Try this:

Class extending WCMUsepojo

----------------

GetResourceResolverService getService = getSlingScriptHelper().getService(GetResourceResolverService.class);

if(getService ==null)

return;

resourceResolver= getService.getServiceResourceResolver("core-admin");// core-admin is the service name ,                                                                       //resourceResolverParams.put(ResourceResolverFactory.SUBSERVICE,"core-admin")

Resource resource = resourceResolver.resolve(resourcePath);

GetResourceResolverService  class

-----------------------------------------------

@component(name="",service=GetResourceResolverService  .class,immediate=true)

public class GetResourceResolverServiceImpl implements GetResourceResolverService {

@Reference

private ResourceResolverFactory resolverFactory;

private ResourceResolver resourceResolver;

@Override

public ResourceResolver getServiceResourceResolver(String subServiceName){

final Map<String,Object> serviceMap = new ConcurrentHashMap<>();

serviceMap.put(ResourceResolverFactory .SUBSERVICE,subServiceName);

try{

resourceResolver = resolverFactory.getServiceResourceResolver(serviceMap);

}catch(LoginException e)

}

}

31 replies

joerghoh
Employee
August 24, 2018

Can you please give more details? What path exactly is not working on publish? Do you have an exception you can share?

Jörg

New Participant
August 24, 2018

Hi All,

I was also getting the same problem and I applied the solution suggested here. Thanks, it worked

It was working in AEM6.2 without any permission to Sling-scripting user but in AEM6.4, we have to give this permission to make it work.

Now it is working in Author but in publish, it is still giving me same issue. it is unable to read tags/child resources/nodes  in publish but it is working in Author environment.

P.S. We have recently upgraded our AEM version from AEM6.2 to AEM6.4

Could you please help me in fixing this in publish mode too and getting the root cause of this issue why it was working in AEm6.2 but not in 6.4

New Participant
August 24, 2018

Hi All,

I was also getting the same problem and I applied the solution suggested here. Thanks, it worked

It was working in AEM6.2 without any permission to Sling-scripting user but in AEM6.4, we have to give this permission to make it work.

Now it is working in Author but in publish, it is still giving me same issue. it is unable to read tags/child resources/nodes  in publish but it is working in Author environment.

P.S. We have recently upgraded our AEM version from AEM6.2 to AEM6.4

Could you please help me in fixing this in publish mode too and getting the root cause of this issue why it was working in AEm6.2 but not in 6.4

joerghoh
Employee
May 22, 2018

Well, Sling Model or WcmUsePojo doesn't matter in this case :-) And migrating from one to the other does not help, as you still be in the context of Sling Scripting, that means that you get a Sling-Scripting resourceresolver.

Instead I would rather question your approach. Why do you need to open a new resource resolver in the context of a WcmUsePojo? Is the resourceresolver you have at hand not sufficient? If not, you are likely to develop complex logic, and I wonder if this complex logic belongs to a model, or if it would better be accessed as an OSGI service.

regards,
Jörg

New Participant
May 21, 2018

Yeah it is not a sling model but a wcmusepojo class that is being used, do you think i just migrate code over to use sling model?

joerghoh
Employee
May 21, 2018

Hm, then the only explanation I have is that you run this code inside a Sling Model. Can you confirm?

And if you run it inside a Sling Model, I wonder why the already provided ResourceResolver isn't sufficient, and you open a new ResourcerResolver instead.

regards,

Jörg

New Participant
May 21, 2018

Hi Jorg,

What do you think?

New Participant
May 18, 2018

So i see the permissions as part of the code base, pardon my earlier statement.

And i also see that the admin-service is  a user with complete privilege as admin,

I also tried knocking org.apache.sling.scripting.core off from the run mode config for the service amendment but in vain.

Resourceresolver.getUserId() - returns sling-scripting

I see this in settings,

bundlesymbolicname / core-admin / admin-service

    org.apache.sling.scripting.core / core-admin / admin-service

  communities-acl-manager

arunpatidar
New Participant
May 18, 2018

Hi Jorg,

I was also surprised after getting sling-scripting as result of session.getUserID()

I can see  User Mapping for this user used for sightly. Not sure if this could be the reason.

but this behaviour is strange.

Arun Patidar
joerghoh
Employee
May 18, 2018

You want to use the service user "core-admin" which should be associated to your bundle. Can you check in the OSGI Webconsole -> Status -> Sling Service User Mappings if the service user "core-admin" is listed?

I don't understand why a change to the sling-scripting serviceuser helped. Can you check via "resourceResolver.getUserId" which user you use in that resourceResolver?

Jörg