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

AEM 6.4 unable to access content path via resourceresolver/session

  • May 17, 2018
  • 31 replies
  • 14157 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

Level 9
May 18, 2018

It was surprising to me as well.

It could detect the presence of /apps but not /content and it was due to permissions that i ended setting up.

Here's the code

This is in the WCMUsePojo class

        resourceResolverParams.put(ResourceResolverFactory.SUBSERVICE, "core-admin");

ResourceResolverFactory rrf = getSlingScriptHelper().getService(ResourceResolverFactory.class);

resourceResolver = rrf.getServiceResourceResolver(resourceResolverParams);

if(resourceResolver!=null)

        log.info("resourceresolver not null"); //It is not null with or without the core-admin subservice name

session = resourceResolver.adaptTo(Session.class);

if(session.nodeExists(path))// able to access paths under /apps but not under /content

Also,

I tried not setting a subservice config and user in user admin and i thought it still worked with the sling-scripting-read permission(without subservice config) and it did not work without the read permission on sling-scripting(without subservice config) .

Is this a bug or am i missing something?

joerghoh
Adobe Employee
Adobe 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

arunpatidar
Community Advisor
Community Advisor
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
Level 9
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

Level 9
May 21, 2018

Hi Jorg,

What do you think?

joerghoh
Adobe Employee
Adobe 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

Level 9
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
Adobe Employee
Adobe 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

Level 2
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

Level 2
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