I am trying to create session using resourceresolver and system user. I am able to get the session object but when I try to fetch the userid from session, it shows anonymous instead of system user used. Below is the code:
resolver = resourceResolverFactory.getResourceResolver(params);
session = resolver.adaptTo(Session.class);
String userId = session.getUserID(); // returns anonymous user instead of system user
This code is a part of OSGI servlet which invokes for specific paths.
Is there something wrong in the code or it is a bug?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
It is not a bug.
I tired in AEM 6.3 Publish instance, its world fine and I am able to get session from subservience user.
Your 3 line of code is also looks ok. May be wrong with service user permission or mapping.
You can check below sample code
aem63app-repo/SeesionInServletWithSubservice.java at master · arunpatidar02/aem63app-repo · GitHub
Thanks
Arun
Views
Replies
Total Likes
Hi,
It is not a bug.
I tired in AEM 6.3 Publish instance, its world fine and I am able to get session from subservience user.
Your 3 line of code is also looks ok. May be wrong with service user permission or mapping.
You can check below sample code
aem63app-repo/SeesionInServletWithSubservice.java at master · arunpatidar02/aem63app-repo · GitHub
Thanks
Arun
Views
Replies
Total Likes
Hi Arun,
I verified the permissions of service user in user mapper and it looks ok. If there was some issue with service user permission then I guess getResourceResolver call should throw loginexception instead of creating a session with anonymous user. One difference I see in my code and your java class is that I am extending SlingAllMethodsServlet instead of SlingSafeMethodServlet otherwise rest everything looks same. And I don't feel that this might be creating any issue here.
Thanks,
Rajeev
Views
Replies
Total Likes
We posted a new video on this...
Views
Replies
Total Likes
Did you try in Author? Would not it work in author instance? I am trying in author.
Views
Replies
Total Likes
Hi Arun/@smacdonald2008,
I was able to figure out the issue.
We were calling getResourceResolver method on resourceresolverfactory and this is returning anonymous user. If we call get ServiceResourceResolver then it returns proper service user and works like a charm. Seems like former method works only with user and password in map not with service user map.
Thanks,
Rajeev
Views
Replies
Total Likes
glad you got it working.
Views
Replies
Total Likes