This issue is related to get a resource with the help of system user ("someuser") having all permissions given to that user in AEM 6.4. below is the code snippet:
In configuration, my system user is defined as "someuser" against the bundle. But, for below code I am doing resourceResolver.get UserId() giving me //sling-scripting. It should give me "someuser".
ResourceResolverFactory resourceResolverFactory = sling.getService(ResourceResolverFactory.class);
ResourceResolver systemResourceResolver = resourceResolver;
if (!(resourceResolverFactory == null)) {
Map<String, Object> authenticationInfo = new HashMap<>();
authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, "bundlevalidation");
systemResourceResolver = resourceResolverFactory.getServiceResourceResolver(authenticationInfo);
}
String pagePath = slingRequest.getRequestPathInfo().getSuffix();
Resource contentBundleResource = null;
if (pagePath != null) {
Resource res = systemResourceResolver.getResource(validPagePath);
}
I debugged all variables above defined, only res is coming as null.
This code is working fine in AEM 6.1. But creating issue in 6.4.
What code change do I need to make for getting that resource.
I studied below link but didn't get much information:
AEM 6.4 unable to access content path via resourceresolver/session
Also, I have this code written in JSP file.
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
OK, I understand your case.
The "problem" is the case, that the JSP does not run in the context of your bundle, but in the context of the sling-scripting engine. Thus every call of
authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, "bundlevalidation");
systemResourceResolver = resourceResolverFactory.getServiceResourceResolver(authenticationInfo);
will lookup the subservice for the sling scripting engine bundle, but not yours. For this bundle only the "sling-scripting" user is defined.
What you can do to make your code working:
I would prefer the second option, because all this sounds too much of business logic, which can be much easier unittested when the code lives inside a bundle instead of a JSP.
Views
Replies
Total Likes
It's not clear for me, where you get the "resourceResolver" from. And on which of the 2 resourceResolvers you have in the above code your call this method at all. Can you please elaborate?
"sling-scripting" is the system user, which is used to resolve the rendering scripts. JSPs are running inside the JSP scripting engine; if you open a new ServiceResolver with the code above, you'll get a resource resolver owned by sling-scripting. This is not a bug but a change introduced with (IIRC) AEM 6.2.
And to be honest, I don't think that opening a new resource Resolver is code which belongs into a JSP. That's something I would put into a service and a bundle.
Views
Replies
Total Likes
Mistakenly I have written resourceResolver, I was talking about systemResourceResolver.
In configuration, my system user is defined as "someuser" against the bundle. But, for above code when I am doing systemResourceResolver.get UserId() giving me //sling-scripting. It should give me "someuser".
systemResourceResolver.get UserId()
actual Result: "sling-scripting"
Expected Result: "someuser"
Views
Replies
Total Likes
OK, I understand your case.
The "problem" is the case, that the JSP does not run in the context of your bundle, but in the context of the sling-scripting engine. Thus every call of
authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, "bundlevalidation");
systemResourceResolver = resourceResolverFactory.getServiceResourceResolver(authenticationInfo);
will lookup the subservice for the sling scripting engine bundle, but not yours. For this bundle only the "sling-scripting" user is defined.
What you can do to make your code working:
I would prefer the second option, because all this sounds too much of business logic, which can be much easier unittested when the code lives inside a bundle instead of a JSP.
Views
Replies
Total Likes
Thanks a lot for giving your time and reply again. It resolved my issue, great help....
Views
Replies
Total Likes
Try to write this code in Java as shown here -- Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data
You can see the video that shows this use working.
Views
Replies
Total Likes