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

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

AEM 6.4 unable to access content path via resourceresolver/session

Avatar

Level 9

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 9

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

Avatar

Employee Advisor

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

Jörg

Avatar

Correct answer by
Level 9

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)

}

}

Avatar

Employee Advisor

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

Avatar

Level 9

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

Avatar

Level 9

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

Avatar

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?

Avatar

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.

Avatar

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.