RE: Logout events not working in openSSO.

Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Hi Everyone,
I am using liferay 6.2 . I wanted  to perform some task when the user logs out. But, since i am using openSSO configuration, the  " logout.events.post " does not seem to be called or run. Without the " openSSO ", the logout events seems to work pretty fine. So, please can someone help in how can i perform custom  logout events for  "openSSO".
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Well, been awhile that I had to do with OpenSSO. Same with 6.2 actually.
How do you do the logout?
I mean, do you send the user to /c/portal/login or do you send him to /opensso/UI/Logout?goto=...?
Or do you use an Agent with a filter (that's what I did since I never could keep the session times in sync).
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Hi Christoph,
I am sending the user to c/portal/logout . 
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
As far as I remember, c/portal/logout redirects to the opensso logout url. Maybe it probably doesn't trigger the logout event.
Hmm, do you get the LOGOUT_EVENTS_PRE event?
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
I just looked into the code:
https://github.com/liferay/liferay-portal/blob/6.2.x/portal-impl/src/com/liferay/portal/servlet/filters/sso/opensso/OpenSSOFilter.java
I believe, it just doesn't trigger those events at all and just destroys the session.
It would need to call the EventsProcessor.
https://github.com/liferay/liferay-portal/blob/6.2.x/portal-impl/src/com/liferay/portal/action/LogoutAction.java
I am not sure, how to solve that. If you are an Enterprise customer, you could try opening a ticket.
If you are CE, well, if it were me, I would probably just clone the repository, change the code and replace the class file with my own version.
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Hi Christoph,
I was just going through different ways i can perform that logout operation in openSSO. And I noticed one thing !! The Session Expiry Action gets called at the time of logout also!! And When I am logging out in openSSO, though it is not redirecting to "logout.events.pre" but it is surely going in "SessionExpiryAction". Then I tried performing the operation in the Session Expiry Action, but I getting NULL user there. Now, if there anyhow I can get the user, my work will be  sorted out. Though there are ways like getting the user id at login time and using that  userId as global variable, but then comes the problem of multiple users login, So i need to figure out some way how can I get the UserId in Session Expiry Action itself. If you have any idea then please help me out !!
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
I am not sure what you mean with SessionExpiryAction. Do you mean, you have implemented an HttpSessionListener? In that case, you should be able to fetch the session from the event and fetch the user from the session.
I am not sure, which attribute you need to fetch, I would probably just print the attribute names, something useful should be in there.
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
I have tried a lot, but I am not able to get the user from the session. Also, i tried implementing the above code you sent  but there are no "org.apache.struts.action" library in my liferay 6.2 so I am not able to use "ActionMapping" ,  "ActionForm" and "ActionForward" emoticon  But if I can find the user using  HttpSession , then my motive could be accheived..
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Hi christoph,
I think I found the solution, I  made  the "login.events.post"action and there As the user logs in at that time I am taking out session with the help of "httprequest" and then setting the user id with the help of session.setAttribute("uid",userId) .Then at the time of sessionexpiry I am getting the user id from session.getAttribute("uid"); !!!!!! It seems to work fine. Let me know if this approach can create some problem or not!!
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
This approach should work.
But I am a bit confused that the session doesn't already contain the userId.  Have you tried to enumerate the session attributes and print them?
Could you try e.g.:
session.getAttribute("open.sso.subject.id");
Note: This works only when you login using opensso. Your solution should work always, no matter the login method.
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Ok Thanks Christoph.
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
thanks christoph ,
 let me give it a try..