Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM 6.4 unable to access content path via resourceresolver/session

NitroHazeDev
Level 7
Level 7

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
NitroHazeDev
Correct answer by
Level 7
Level 7

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

0 Replies
Jörg_Hoh
Employee
Employee

Can you please give more details? What path exactly is not working on publish? Do you have an exception you can share?

Jörg

NitroHazeDev
Correct answer by
Level 7
Level 7

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

Jörg_Hoh
Employee
Employee

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

NitroHazeDev
Level 7
Level 7

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

NitroHazeDev
Level 7
Level 7

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

Feike_Visser1
Employee
Employee

Still request.getResourceResolver() always has my preference

pankajkdhingra
Level 3
Level 3

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?

Feike_Visser1
Employee
Employee

most likely due to changed permissions between 6.2 and 6.4

pankajkdhingra
Level 3
Level 3

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.

saurabhs5999723
Level 2
Level 2

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.