Session Sharing in Liferay #

The private-session-attributes settings in liferay-portlet.xml determines what session your JSR168 deployed portals will use. This setting affects the sharing of APPLICATION_SCOPE session attributes between the portal, portlets (in the same WAR, and across different WARs) and the servlets in these WARs.

Sharing of session attributes from the portal to private portlets is also determined by the session.shared.attributes setting, which you can override in your portal-ext.properties file. Session attributes with the configured prefix on the portal session will be visible from any private portlets too.

Summary #

  • Non-private portlets read and write to the Portal session.
  • Private portlets write to their own WAR session.
  • Private portlets can read shared attributes of the Portal session. They try to read from their own WAR session first, then looks up any shared attributes copied from the Portal session.
  • Normal servlets only have access to the WAR session, and cannot directly access the Portal session. In order to read shared session attributes, servlets need a private portlet in the same WAR file to copy it for them. Or you can configure your servlet to use the portal session by using Liferay's PortalDelegateServlet mechanism.

For an in depth explaination including diagrams, see my blog posts here:

http://longgoldenears.blogspot.com/2008/03/liferay-session-sharing-demystified.html

http://longgoldenears.blogspot.com/2008/03/portaldelegateservlet-servlet-session.html

0 附件
56767 查看
平均 (1 投票)
满分为 5,平均得分为 3.0。
评论
讨论主题回复 作者 日期
khó hieeueu quá Nguyen Le 2012年5月18日 上午12:37
is this still valid in liferay 6.1 ?? the denu 2012年10月19日 上午8:44
I am also having the same question. Is this... Sushil Saini 2012年10月22日 下午4:43
Hi Friends,.... Regarding the question. Is this... Sushil Saini 2012年10月24日 上午3:23

在 12-5-18 上午12:37 发帖。
is this still valid in liferay 6.1 ??
在 12-10-19 上午8:44 发帖。
I am also having the same question. Is this still valid in liferay 6.1.1 ?

Because, I have tried the session sharing between portal and servlet using above mentioned way of configuration in liferay version 6.0.6 CE and it worked. ... But now we have upgraded the version of life-ray from 6.0.6 to 6.1.1. And session sharing is not working any more.

Can anyone please help me on this. I am really stuck with it.

Thanks
Sushil Saini
在 12-10-22 下午4:43 发帖。
Hi Friends,.... Regarding the question. Is this still valid in the liferay 6.1.1? ... Answer is yes this is valid in liferay 6.1.1 except a specific scenario ...... which i found, was working in older versions of the liferay but is not working on the liferay 6.1.1.

Scenario: For sharing the session between portlet and servlet declared the portlet as private which is the default settings of the portlet or we can make it by setting private-session-attributes to true in liferay-portlet.xml file. Now the session variables set in APPLICATION_SCOPE by portlet action are accessible by servlet.
But when name of the session variable starts with keyword which defined in property session.shared.attributes in portal-ext.properties file (eg session.shared.attributes= LIFERAY_SHARED, variable name is LIFERAY_SHARED_userid ). In this case the session variable is not accessible in the servlet.
This scenario is working fine with the older versions of liferay but not working with the liferay 6.1.1.

Cheers.
在 12-10-24 上午3:23 发帖以回复 Sushil Kumar Saini