How to signout programmatically from Liferay custom portlet

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


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.

Logout Programmatically - Clearing the cookies , Any Suggestions to clear the cookies for whole portal in a custom portlet? HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); Writing a Custom Login Portlet If you need to customize your users’ authentication experience completely, you can write your own Login Portlet. The mechanics of this on the macro level are no different from writing any other portlet, so if you need to familiarize yourself with that, please see the portlets section of tutorials .


I also did not find a way to send a specific redirect by using liferay's default logout (/c/portal/logout). So I logged out the user programmatically with the util class AuthenticatedSessionManagerUtil and afterwards sending a specific redirect location within the response object, e.g. response.sendRedirect(yourLocation)

Note: With Liferay 7.2 I used AuthenticatedSessionManagerUtil.signOutSimultaneousLogins(userId) instead of AuthenticatedSessionManagerUtil.logout(userId) which did not work for me. hth

Writing a Custom Login Portlet – Liferay Help Center, If you need to customize your users' authentication experience completely, you can write your own Login Portlet. The mechanics of this on Note that because your custom built SDKs contain only the client libraries for calling your custom portlet services, you must install them alongside Liferay’s prebuilt SDK. Liferay’s prebuilt SDK contains additional classes that are required to construct any remote service call.


You can redirect to c/portal/logout more precisely :

actionResponse.sendRedirect("/c/portal/logout/");

Portal Properties - Description, Set this to true to enable programmatic configuration to let the Portlet TCK obtain Set this to true to log out the user from CAS when the portal session expires. As you see XYZPortlet is the id of the portlet defined in liferay-portlet.xml, liferay-display.xml which remains same for all the portlets I add to the reports page. I want to dynamically assign a new Id to the portlet instance and install it permanently to the dashboard layout.


Just leaving this here after facing this problem (LR7):

    try {
        AuthenticatedSessionManagerUtil.logout(request, response);

        request.setAttribute(WebKeys.LOGOUT, true);

    }

2. portal.properties, If set to true, then portlets can only be dynamically added to a page if it contains a proper Set the default logout page path for users relative to the server path. RE: Liferay 6.2 custom login portlet Liferay Legend Posts: 5757 Join Date: 9/23/08 Recent Posts I'm curious to learn why everybody seems to need their own custom login portlet.


All you have to do is

perform operation: at the end of operation use this:

HttpSession session = PortalUtil.getHttpServletRequest(request).getSession();
session.invalidate();


try {
    System.out.println(" redirecting to the required page");
                    response.sendRedirect(themeDisplay.getPortalURL() + "/page-on-which-to-be-redirected");

    } catch (IOException e1) {

          e1.printStackTrace();
        }

Notes for developing the custom login portlet in Liferay – Liferay Portal, If set to true, then portlets can only be dynamically added to a page if it contains the default logout page to be http://localhost:8080/web/guest/logout, set this to� Each portal instance can have its own overridden property file following the convention portal-companyWebId.properties. To enable this feature, set the "company-id-properties" system property to true.


The portal-ext.properties File (Project WebSynergy Milestone 4 , The main configuration file for Liferay Portal is portal.properties, which programmatic configuration to let the # Portlet TCK obtain a URL for each test. auto.deploy.custom.portlet.xml=false # # Set this to 1 if you are using JBoss' PrefixDeploymentSorter. LogoutPreAction logout.events.post=com.liferay. portal.events. Liferay Custom Fields or Liferay Custom Attribute is a feature in Liferay. Liferay provides UI and API to allow for the creation of customized fields associated with any entity generated by Service Builder. These fields provide extensibility without the need for extending the Liferay DB schema.


Custom Action(Events) Hook in Liferay, If you are developing the custom login portlet some of the following Liferay Add following configuration in liferay-portlet.xml file private-session-attribute is set to Set the default logout page path for users relative to the server path. is set to true, so that login portlet can be dynamically added to page. I added a custom user field in Liferay, and set a value on a specific user. How can I access this value programmatically? If I try this, I always get null: String customAttr = (String)user.getExpandoBridge().getAttribute("customAttr"); user.getExpandoBridge().getAttribute("customAttr") returns a value of Type java.IO.Serializable.


Set the following to true to enable programmatic configuration to let the Portlet TCK obtain a LogoutPostAction logout.events.post=com.liferay.portal.events. Setting custom portlet titles in Liferay can be a little tricky. Changing the title via the portlet configuration in the frontend is easy but when it comes to reading the custom title property programmatically things seem to get a little messy. Setting the Title. So, first of set your portlet title as usual via the portlet configuration in the