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

New Participant
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
Employee
May 18, 2018

I wonder why the sling-scripting service user is used for your resourceResolver. How do your resourceResolverParams look like?

And btw: it's correct that the sling-scripting service-user does not have read access to /content. You should not change that permission.

kind regards,

Jörg

New Participant
May 18, 2018

Thanks .. but i see OOTB there are no permissions set for the sling-scripting user account. The code does not alter any permissions.

Attaching the snapshot i see OOTB where there are no permissions under /content

akhoury
Employee
May 17, 2018

Since you found that a system user permission was missing you might want to repair all the system user permissions.  Somebody most likely installed a package containing ACLs which overwrote the out-of-the-box ones.  There are probably other users that might be missing their permissions.  See this article for a guide on how to repair system user ACLs: Fix missing system user ACLs

New Participant
May 17, 2018

Sling scripting user had no read permission, thanks guys that did it.

New Participant
May 17, 2018

Hey Guys,

The user does have read permissions under /content , /apps, /etc infact gave admin privilege for testing. So other than apps, it appears that node does not exist for any other path

arunpatidar
New Participant
May 17, 2018

yes Jorg is right, the issue is seems with permission.

Check permission of sling-scripting user for /content/ folder.

Arun Patidar
joerghoh
Employee
May 17, 2018

The only reason for the described behaviour is no read permissions on /content. Please double-check that.

Jörg

New Participant
May 17, 2018

So i am using the regular way of accessing it ... it says node exists for path under apps. This works in 6.2 and not in 6.4

In WCMUse pojo class:

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

resourceResolver = rrf.getServiceResourceResolver(resourceResolverParams);//pass subservice name

if(resourceResolver!=null)

        log.info("resourceresolver not null"); // not null

session = resourceResolver.adaptTo(Session.class);

if(session.nodeExists(path))

arunpatidar
New Participant
May 17, 2018

Hi,

How are you getting session? Could you please share your code?

Arun Patidar