Foros de discusión

Logout Programmatically - Clearing the cookies

venka reddy, modificado hace 9 años.

Logout Programmatically - Clearing the cookies

Regular Member Mensajes: 231 Fecha de incorporación: 23/03/11 Mensajes recientes
Hi,

I am trying to logout the user programmatically , So I am trying to clear cookies. But not able to clear cookie and also user doesn't logout .

Here is the following snippets.

Cookie[] cookies = actionRequest.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
cookies.setValue("");
cookies.setPath("/");
cookies.setMaxAge(0);
actionResponse.addProperty(cookies);
}
}

Is anything i am going wrong?
thumbnail
David H Nebinger, modificado hace 9 años.

RE: Logout Programmatically - Clearing the cookies

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
Cookies on the action request is just for the portlet and does not affect the overall state of login.
venka reddy, modificado hace 9 años.

RE: Logout Programmatically - Clearing the cookies

Regular Member Mensajes: 231 Fecha de incorporación: 23/03/11 Mensajes recientes
hi david,

so i have tried casting actionRequest to httpservlet request. It is not clearing the cookies.

Below is the code i have tried. Any Suggestions to clear the cookies for whole portal in a custom portlet?

HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
HttpSession session = request.getSession();

Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
cookies.setValue("");
cookies.setPath("/");
cookies.setMaxAge(0);
response.addCookie(cookies);
}
}
thumbnail
Meera Prince, modificado hace 9 años.

RE: Logout Programmatically - Clearing the cookies

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
thumbnail
Rahul Pande, modificado hace 9 años.

RE: Logout Programmatically - Clearing the cookies

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
venka reddy:

I am trying to logout the user programmatically


Hi Venka,

You can Liferay's default method for logging out the user i.e by calling c/portal/logout instead of manually removing the cookies.

HTH
Rahul Pande
venka reddy, modificado hace 9 años.

RE: Logout Programmatically - Clearing the cookies

Regular Member Mensajes: 231 Fecha de incorporación: 23/03/11 Mensajes recientes
Hi Rahul,

By Calling "c/portal/logout" it is working . But i need to redirect to the custom jsp page after logout. so i am trying to clear cookies programatically which is not happening.

Any suggestions on this?
thumbnail
Anil Sunkari, modificado hace 9 años.

RE: Logout Programmatically - Clearing the cookies

Expert Mensajes: 427 Fecha de incorporación: 12/08/09 Mensajes recientes
Hi Venka,

I think after "c/portal/logout" using custompostlogoutaction you can redirect to your own/custom.

Refer : https://www.liferay.com/community/forums/-/message_boards/message/14111757

Regards,
Anil Sunkari
thumbnail
Rahul Pande, modificado hace 9 años.

RE: Logout Programmatically - Clearing the cookies

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
venka reddy:


But i need to redirect to the custom jsp page after logout. so i am trying to clear cookies programmatically which is not happening.

Any suggestions on this?


Please try setting this property in portal-ext.properties if you want to redirect user to a specific Liferay page.


##
## Default Logout Page
##

    #
    # Set the default logout page path for users relative to the server path.
    # This is the page users are automatically redirected to after logging out.
    # For example, if you want the default logout page to be
    # http://localhost:8080/web/guest/logout, set this to /web/guest/logout. To
    # activate this feature, set auth.forward.by.last.path to true. To customize
    # the behavior, see com.liferay.portal.events.DefaultLogoutPageAction in
    # the "logout.events.post" property above.
    #
    default.logout.page.path=
    #default.logout.page.path=/web/guest/logout



HTH
Rahul Pande