When developing we've come across the permissions/dispatcher issue of the getResource() method breaking page.
These forums suggested that we needed to use resolve() method instead of the getResource() method and that does work, but I am more interested in why that works.
I understand that it has to do with not having the appropriate permissions, because you might be trying to get a resource that an anonymous user does not have access to.
But in the end, they both return a Resource.
Can anyone explain the differences between the two methods and why one works with anonymous permissions and one does not. I have read the documentation multiple times, located here, but it doesn't quite make complete sense to me. Just trying to understand the JCR resourceResolver a little better.
Thanks!
Solved! Go to Solution.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Hi,
One more difference that I can find is that getResource() method returns null if the resource does not exist in the repository whereas the resolve() method returns the instance of the NonExistingResource if the resource does not exist where this NonExistingResource instance can further be used to create that resource.
Thanks!
Nupur
My question is more about what is happening behind these methods I suppose.
Why does one fail on publish and on does not.
The resolve() method will work on publish instances when not logged in, and the getResource() will not. I am more curious on why that is? How is the algorithm on how these two methods get the resource different? Does one use the user session and one does not?
you can look up the code for ResourceResolver on grepcode[1]. by the looks of it, getResource() makes use of ResourceResolverContext[2]. ResourceResolverContext takes into account the logged in user info.
I couldn't find any such requirement in resolve() method. that being said, you can delve into the code and look.
happy hunting
Views
Replies
Total Likes
Views
Likes
Replies