Blogs

Blogs

How to configure user session timeout in Liferay Portal

Overview

The Liferay Portal user session timeout is defined by the session timeout value.

The article outlines potential solutions for configuring the user session timeout (see Solutions below).

Background

The session timeout is loaded by method "checkWebSettings" in Liferay Portal Java class  com.liferay.portal.servlet.MainServlet.

The session timeout property value is loaded in the following order:

1/ Property “session.timeout” in property file “portal.properties”

NOTE: The default path for the “portal.properties” file in a Liferay Portal + Apache Tomcat bundle is “LIFERAY_HOME/tomcat/webapps/ROOT/WEB-INF/portal-impl.jar”.

2/ Property “session.timeout” in property file "LIFERAY_HOME/portal-ext.properties”

NOTE: The default path for the “portal-ext.properties” file in a Liferay Portal + Apache Tomcat bundle is “LIFERAY_HOME”.

{code}
    #
    # Specify the number of minutes before a session expires. 
    # This value is always overridden by the value set in web.xml.
    #
    session.timeout=30
{code}

NOTE: The “session.timeout” property is always overridden by the value set in web.xml.

3/ Web config element “session-timeout” in file “web.xml”

NOTE: The default path for the “web.xml” file in a Liferay Portal + Apache Tomcat bundle is “LIFERAY_HOME/tomcat/webapps/ROOT/WEB-INF/web.xml”.

<session-config>
   <session-timeout>30</session-timeout>
</session-config>


NOTE: The session timeout is loaded by the MainServlet. Refer to Java class “com.liferay.portal.servlet.MainServlet#checkWebSettings”

Configuration Options

Following are potential configuration options for configuring the user session timeout.

Option 1 - Over-ride web.xml in deployed Liferay Portal web app

Update session timeout value in <session-timeout> element.
e.g. 8 hours = 480 minutes

FILE: LIFERAY_HOME/tomcat/webapps/WEB-INF/web.xml

<session-config>
   <session-timeout>480</session-timeout>
</session-config>


NOTE: This approach is not recommended as the web.xml file can be over-ridden when applying Liferay Portal patches using the Liferay Portal patching tool.

Option 2 - Over-ride session timeout value in web.xml using portal EXT plugin

NOTE: This approach may not work due to the Liferay Portal patching process (TBC).

Update session timeout value in <session-timeout> element
e.g. 8 hours = 480 minutes

FILE: EXT_PLUGIN/.../WEB-INF/web.xml

<session-config>
   <session-timeout>480</session-timeout>
</session-config>

Option 3 - Remove session timeout value in web.xml using portal EXT plugin

NOTE: This approach may not work due to the Liferay Portal patching process (TBC).

Remove session timeout value and <session-timeout> element from parent <session-config> element

<session-config>
</session-config>

NOTE: This approach will ensure the value defined in portal-ext.properties is retained.
 

References

Related LPS Tickets

Related Articles

 

Hey Tim,

you could improve this article:

 

- replace the file name "portal.properties" with "web.xml" in this section:

Solution 3/ Web config element “session-timeout” in file “web.xml”.

NOTE: The default path for the “portal.properties" file in a Liferay Portal + Apache Tomcat bundle is “LIFERAY_HOME/tomcat/webapps/ROOT/WEB-INF/web.xml”.

 

- and am I wrong. but - "eg. 2 hours = 480 minutes" should be 120 minutes?

 

- You talked about "portal EXT plugin", why aren't you refering to an article of it like: https://portal.liferay.dev/docs/7-0/tutorials/-/knowledge_base/t/advanced-customization-with-ext-plugins

 

- is there a reason that this value isn't implemented inside liferay configuration GUI yet? I mean, this is pretty much work for such a small adjustment? A small section that describes why this configuration has to be made inside web.xml would be nice.

 

- when working with docker it's not that easy to simply replace some tomcat files like web.xml. It would be great if you just add information or tipps or even just a hint to mount that web.xml file maybe? Idk

 

 

Team EWERK

 

 

Thanks, Torsten.

 

I have updated the article with some of your feedback.

 

Packaging and managing the web config file (web.xml) is different with every JEE/J2EE servlet container, including Apache Tomcat. I have discovered every Liferay Portal/DXP environment and the operational requirements are different. There is no "best" way to manage the config, hence I have not provided an suggestions here. I hope the article has been helpful and I appreciate you taking the time to provide feedback.

 

Regards,

 

Tim