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

saurabhs5999723
Level 2
May 9, 2019 11:06 PM UTC

Hey,

I want to understand how this code is different than your old code.

Here you have a new class and method to get the resource resolver. But in the class, you are using resource resolver factory to get the resource resolve.

So logically whats the difference. I just want to understand that.

Translate
Level 2
Aug 27, 2018 12:07 PM UTC

feike_visser

could you please explain what kind of permissions has been changed from AEM6.2 to AEM6.4 ?

Actually, We need to follow the same practice in Stage/PROD and we have too much content in PROD, it could be risky approach and may bring some issues in the live site.

Translate
Feike_Visser1
Employee
Aug 27, 2018 11:37 AM UTC

most likely due to changed permissions between 6.2 and 6.4

Translate
Level 2
Aug 27, 2018 11:32 AM UTC

It was null pointer error in publish environment on the same code in the author as it was not able to get resources at the location/child page.

it got fixed now as I have created a package of permissions and replicated on publish environment with "Merge" type.

but I am unable to understand how it was working in AEM6.2 but didn't work when we moved the code base from AEM6.2 to AEM6.4?

Translate
Feike_Visser1
Employee
Aug 27, 2018 6:00 AM UTC

Still request.getResourceResolver() always has my preference

Translate
Level 9
Aug 27, 2018 2:00 AM UTC

feike_visser​: i would definitely want to keep that in mind.. nice to know.. thank you so very much

Translate
Level 9
Aug 27, 2018 1:59 AM UTC

I was surprised .. and i knew editing permissions for sling scripting giving permissions to code under apps is not the right way , thanks to people to pointed out against it....So apparently in 6.2 sling scripting user with certain privileges were used to access classes that extend wcmuspojo, i raised a ticket with daycare and they suggested this which helped me resolve the issue. This is the solution they provided and it worked for me

Translate
joerghoh
Employee
Aug 25, 2018 4:43 PM UTC

Still I don't understand why you need a session with more or different privileges when rendering a page.

Translate
Feike_Visser1
Employee
Aug 25, 2018 10:34 AM UTC

I would always AutoClosable when creating a new resolver / session: htl-examples/AutoCloseableService.java at master · heervisscher/htl-examples · GitHub

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

}

}

Translate