AEM 6.3 resourceresolver.adaptto(session.class) issue | Community
Skip to main content
Level 4
Aug 2, 2018 4:40 PM UTC
Solved

AEM 6.3 resourceresolver.adaptto(session.class) issue

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.
arunpatidar
arunpatidarAccepted solution
New Participant
Aug 2, 2018 5:12 PM UTC

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

6 replies

smacdonald2008
Level 10
Aug 9, 2018 3:44 PM UTC

glad you got it working.

Translate
Level 4
Aug 9, 2018 3:37 PM UTC

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

Translate
Level 4
Aug 9, 2018 3:16 PM UTC

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

Translate
smacdonald2008
Level 10
Aug 2, 2018 5:46 PM UTC
Level 4
Aug 2, 2018 5:33 PM UTC

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

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Aug 2, 2018 5:12 PM UTC

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

Translate
Arun Patidar