AEM - Java code needs to access frontend resource ( in /etc.clientlibs) | Community
Skip to main content
Level 6
September 14, 2021
Solved

AEM - Java code needs to access frontend resource ( in /etc.clientlibs)

  • September 14, 2021
  • 5 replies
  • 2596 views

Hi folks,

I have some Java code which needs to write an image to a pdf file.  The image is located in the code, in frontend/src/main/webpack/resources/images/blah.gif/jcr:content.

 

Eventually the build system puts the image at the following location:

/apps/xxx/clientlibs/resources/images/blah.gif/jcr:content

which the proxy servlet maps to

/etc.clientlibs/xxx/clientlibs/resources/images/blah.gif/jcr:content 

 

The Java code works fine on Author ( I assume because I am logged in), but not on the publishers.  Does the "anonymous" user have to have explicit read access permission at the path to the image at /apps/xxx/clientlibs/resources/images/blah.gif/jcr:content ?   

 

tnx 

Fiona

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Fanindra_Surat

Hi @fionas76543059 -

 

To access the AEM system restricted paths in Java code, you will need service resource resolver. You can create a system user with appropriate permissions to the /apps/* path and use this to configure service for fetching the service resource resolver.

 

Some useful links for implementation - 

https://aem4beginner.blogspot.com/how-to-get-resourceresolver-from

http://www.aemcq5tutorials.com/tutorials/resourceresolver-from-resourceresolverfactory/

 

Thanks,

Fani

5 replies

Anny0505
Community Advisor
Community Advisor
September 14, 2021

@fionas76543059 ,

 

Yes. Please give read access to anonymous user to access the image resources on publish instance.

 

Thanks,

Aruna

Fanindra_Surat
Community Advisor
Fanindra_SuratCommunity AdvisorAccepted solution
Community Advisor
September 14, 2021

Hi @fionas76543059 -

 

To access the AEM system restricted paths in Java code, you will need service resource resolver. You can create a system user with appropriate permissions to the /apps/* path and use this to configure service for fetching the service resource resolver.

 

Some useful links for implementation - 

https://aem4beginner.blogspot.com/how-to-get-resourceresolver-from

http://www.aemcq5tutorials.com/tutorials/resourceresolver-from-resourceresolverfactory/

 

Thanks,

Fani

Level 6
September 15, 2021

Thanks all !

 

I will go with the new  system user option for the Java code then as this seems to be the safest.

 

 

Asutosh_Jena_
Community Advisor
Community Advisor
September 15, 2021

Hi @fionas76543059 

 

If you are accessing the resource using /etc.clientlibs/xxxx then there should not be any permission issue as anonymous user should be able to access it using the proxy servlet like the way it's accessing the other clientlib content.

 

Can you check which path the request is being made and then we can check if a system user is really required or if there are any other issue.

 

Thanks!

Level 6
September 15, 2021

hi!

thanks for all the help!

 

I access lots of image in /etc.clientlibs from Javascript programs without problems.

This is from the Java code though and it reads the "data" property on the gif node jcr:content to write it to a PDF.

If I give "anonymous" read permission on /apps/xxxx/clientlibs/resources/images/blah.gif it does work.

When I tried to use /etc.clientlibs/xxx/clientlibs/resouces/images/blah.gif/jcr:content  it didn't work

I'm a bit puzzled!

 

thanks

Fiona

 

Adobe Employee
September 15, 2021

Hi @fionas76543059 ,

 

Have you added allowProxy true on your clientlibs. If not that will be the issue.

 

https://experienceleague.adobe.com/docs/experience-manager-64/developing/introduction/clientlibs.html

 

 

Hope this helps!!
Thanks

kchaurasiya
Level 5
September 15, 2021

@fionas76543059 You can add the allow Proxy on the client-lib. See the snapshot below for the reference.

 

if in case it does not work they create system user and use that system user to read the node values.

Thank you.

 

 

 

Level 6
September 15, 2021

Thanks for all the help.

My  clientlib already has this allowProxy flag set and it works fine for all my Javascript code that also references the images there.

It is only in the Java when I try to read the image to write it into a PDF that I get this "message, javax.jcr.PathNotFoundException: Node with path /etc.clientlibs/xxxx/clientlibs/core/resources/images/hd_PF.gif/jcr:content does not exist."

 

The only thing that has worked for me is too enable "anonymous" to read /apps/xxxx/clientlibs/resources/images/hd_PF.gif/jcr:content.

 

But I don't know if this is a good thing to do.  It is like the Java code doesn't see the proxy servlet stuff