Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Terrence Szeto
Logout Hook not allowing cookie modification
July 28, 2011 8:14 AM
Answer

Terrence Szeto

Rank: New Member

Posts: 5

Join Date: November 9, 2010

Recent Posts

Hi

I have a custom hook created in order to delete one specific cookie that was created as part of a Single Single On session by a J2EE agent.

For whatever reason, any modifications (clear value and set expiry to 0) don't seem to be appearing taking into effect.
My Hook is deployed corrected, and debug statements show the code its being executed, yet the cookie still remains, expiry still in tact and value still there.

Am I doing something wrong?
This should be very simple.

Oh I'm on Liferay EE 6.0.5 and Tomcat, tested on Chrome build 12 and Firefox 5.0.

 1
 2import javax.servlet.http.Cookie;
 3import javax.servlet.http.HttpServletRequest;
 4import javax.servlet.http.HttpServletResponse;
 5
 6import com.liferay.portal.kernel.events.Action;
 7import com.liferay.portal.kernel.events.ActionException;
 8
 9public class CustomPostLogout extends Action {
10
11    @Override
12    public void run(HttpServletRequest arg0, HttpServletResponse arg1)
13            throws ActionException {
14        Cookie[] cookies = arg0.getCookies();
15        for ( int i=0; i < cookies.length; i++ ) {
16            Cookie aCookie = cookies[i];
17            if ( aCookie.getName().equals("iPlanetDirectoryPro") ) {
18                System.out.println("Found iPlanet");
19                aCookie.setValue("");
20                aCookie.setMaxAge(0);
21                arg1.addCookie(aCookie);
22            }
23        }
24    }
25}
Manuel Pinto
RE: Logout Hook not allowing cookie modification
November 15, 2012 9:27 AM
Answer

Manuel Pinto

Rank: New Member

Posts: 4

Join Date: August 20, 2012

Recent Posts

Hi,

I am using liferay 6.1 CE GA2 bundled with JBoss and also found this problem on a custom hook (logout.events.pre) to remove one specific application cookie but the same still remains without any changes.

 1
 2public class CSTPreLogout extends Action {
 3
 4    @Override
 5    public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
 6     ...
 7         Cookie cookie = CSTSSOFilter.getSSOCookie(request, session.getEnvironment());
 8         if (cookie != null) {
 9           cookie.setMaxAge(0);
10           cookie.setPath(StringPool.SLASH);
11           response.addCookie(cookie);
12     }
13    }
14}


Any Idea?

Thanks a lot
Miguel Coxo
RE: Logout Hook not allowing cookie modification
November 15, 2012 2:30 PM
Answer

Miguel Coxo

Rank: New Member

Posts: 16

Join Date: March 1, 2010

Recent Posts

So we finally managed to remove the application cookie.
  1. You need to set the correct domain for the cookie. When you fetch the cookie the domain is blank.
  2. You need to use the method response.addProperty from an ActionResponse to add the cookie.
We ended up not removing the cookie in the Action.
As far as we could test, we can only remove it when we have an ActionResponse.
Advait Trivedi
RE: Logout Hook not allowing cookie modification
April 14, 2013 4:41 PM
Answer

Advait Trivedi

Rank: Junior Member

Posts: 56

Join Date: March 30, 2010

Recent Posts

In my case, I was facing same problem.
Setting path on cookie before resetting it in logout hook did the trick.
Rahul Sharma
RE: Logout Hook not allowing cookie modification
April 15, 2013 6:58 AM
Answer

Rahul Sharma

Rank: Junior Member

Posts: 60

Join Date: January 10, 2012

Recent Posts

Use response.sendRedirect("<path>"),as cookies only modify when the request is again sent to the browser.
Pritesh Shah
RE: Logout Hook not allowing cookie modification
November 25, 2013 10:42 PM
Answer

Pritesh Shah

Rank: Junior Member

Posts: 31

Join Date: July 4, 2012

Recent Posts

Hello Miquel,

I am having same issue, I want to clear/delete/expire one cookie on logout.
Can you please post your solution with snippets/code would help a great ?

Thanks,
Pritesh