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

Moyenne (1 Voter)
L'estimation moyenne est de 3.0 étoiles sur 5.
Commentaires
Réponses Auteur Données
khó hieeueu quá Nguyen Le 18 mai 2012 00:37
is this still valid in liferay 6.1 ?? the denu 19 octobre 2012 08:44
I am also having the same question. Is this... Sushil Saini 22 octobre 2012 16:43
Hi Friends,.... Regarding the question. Is this... Sushil Saini 24 octobre 2012 03:23

Publié le 18/05/12 00:37.
is this still valid in liferay 6.1 ??
Publié le 19/10/12 08: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
Publié le 22/10/12 16: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.
Publié le 24/10/12 03:23 en réponse à Sushil Kumar Saini.