Accessing to the currently logged in user's Session in an HttpServlet | Community
Skip to main content
LinearGradient
Level 6
October 16, 2015
Solved

Accessing to the currently logged in user's Session in an HttpServlet

  • October 16, 2015
  • 1 reply
  • 580 views

Hi,

If I want to implement a servlet that doesn't necessarily map to a resource, is it possible to extend HttpServlet, rather than, for example, SlingAllMethodsServlet, but still access the javax.jcr.Session for the currently logged in user?

Thanks in advance.

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 JustinEd3

Yes, although I'm not sure why you would want to do that. If you just have a regular HttpServlet registered with Sling, you can get the current ResourceResolver by doing:

ResourceResolver resolver = (ResourceResolver) request.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER); Session session = resolver.adaptTo(Session.class)

1 reply

JustinEd3Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

Yes, although I'm not sure why you would want to do that. If you just have a regular HttpServlet registered with Sling, you can get the current ResourceResolver by doing:

ResourceResolver resolver = (ResourceResolver) request.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER); Session session = resolver.adaptTo(Session.class)