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

AEM 6.4 unable to access content path via resourceresolver/session

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.
NitroHazeDevAccepted solution
Level 9
Aug 24, 2018 9:40 PM UTC

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 5:06 PM UTC

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?

Translate
joerghoh
Employee
May 18, 2018 4:55 PM UTC

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

Translate
Level 9
May 18, 2018 2:53 PM UTC

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

Translate
akhoury
Employee
May 17, 2018 11:29 PM UTC

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

Translate
Level 9
May 17, 2018 9:41 PM UTC

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

Translate
Level 9
May 17, 2018 9:27 PM UTC

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

Translate
arunpatidar
New Participant
May 17, 2018 9:21 PM UTC

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

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

Translate
Arun Patidar
joerghoh
Employee
May 17, 2018 8:32 PM UTC

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

Jörg

Translate
Level 9
May 17, 2018 7:08 PM UTC

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))

Translate
arunpatidar
New Participant
May 17, 2018 6:42 PM UTC

Hi,

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

Translate
Arun Patidar