AEM 6.3 resourceresolver.adaptto(session.class) issue | Community
Skip to main content
Level 4
August 2, 2018
Solved

AEM 6.3 resourceresolver.adaptto(session.class) issue

  • August 2, 2018
  • 6 replies
  • 4455 views

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?

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 arunpatidar

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

6 replies

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
August 2, 2018

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

Arun Patidar
Level 4
August 2, 2018

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

smacdonald2008
Level 10
August 2, 2018
Level 4
August 9, 2018

Did you try in Author? Would not it work in author instance? I am trying in author.

Level 4
August 9, 2018

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

smacdonald2008
Level 10
August 9, 2018

glad you got it working.