How to signout programmatically from Liferay custom portlet

liferayliferay-6logout

I am creating a custom portlet.

And I need to log-out the User from the portal after he performs some operation in my custom portlet. I am extending liferay's MVCPortlet.

In one of MyPortlet's action methods I need to write the code to logout the user and then redirect it to the home page.

Update:
I tried the following which I think logs out the user but does not redirect to the home page after logging out:

actionResponse.sendRedirect(PortalUtil.getPortalURL(actionRequest) + "/c/portal/logout");

Thanks All

Best Answer

Well this may be a very late reply, but it may help somebody

Firstly, you have to validate the session and the re-direct to the logout URL. Otherwise, the session remains and the user is moved to the landing page, even though we redirect to the logout url. So, this is what one should do

HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
request.getSession().invalidate();
actionResponse.sendRedirect(themeDisplay.getURLSignOut());

Hope this helps.

Related Topic