Search code examples
sessionliferay

Why I can't read session attribute from portlet that is set in AutoLogin class


I try unsuccessful to access from my portlet the session attribute that I have set during the AutoLogin phase.

Setting attribute in AutoLogin class:

@Override
public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException {
      request.getSession().setAttribute("My-Attribute-Key", "Hello World");
 ...
}

Access attribute from Portlet:

@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
        Object attribute = PortalUtil.getHttpServletRequest(renderRequest).getSession().getAttribute("My-Attribute-Key");
...
}

Solution

  • Take a look at Session Sharing on Liferay Wiki.