Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

AEM 6.4 unable to access content path via resourceresolver/session

Avatar

Level 10

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.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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)

}

}

View solution in original post

31 Replies

Avatar

Community Advisor

Hi,

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



Arun Patidar

Avatar

Level 10

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

Avatar

Employee Advisor

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

Jörg

Avatar

Community Advisor

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

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



Arun Patidar

Avatar

Level 10

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

Avatar

Level 10

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

Avatar

Employee

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

Avatar

Level 10

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

1490207_pastedImage_0.png

Avatar

Employee Advisor

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

Avatar

Level 10

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?

Avatar

Employee Advisor

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

Avatar

Community Advisor

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.

Screen Shot 2018-05-18 at 7.40.10 PM.png



Arun Patidar

Avatar

Level 10

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

Avatar

Employee Advisor

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

Avatar

Level 10

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?

Avatar

Employee Advisor

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

Avatar

Level 3

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

Avatar

Level 3

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