Fórumok

Getting portlet session from its id

thumbnail
Emmanuel Guiton, módosítva 13 év-val korábban

Getting portlet session from its id

Junior Member Bejegyzések: 39 Csatlakozás dátuma: 2010.12.03. Legújabb bejegyzések
Hello all,

I have developed a portlet which includes GWT code, in particular for RPC calls.
I am trying to get the current user in the GWT servlet and I am stucked. I cannot get it directly, e.g.
final HttpServletRequest request = this.getThreadLocalRequest();
final User user = PortalUtil.getUser(request);
returns null;
As far as I understand it, the HttpServletRequest made from the javascript code does not include all the portlet session data that are included in the HttpServletRequest that goes directly through Liferay code.

However, in the GWT servlet, I can get the session id from the HTTP servlet request. This id is also the portlet session id.
Is there any way to get the portlet session from its id ?
I hope to finally get the data I need from the portlet session but I cannot find a mean to get it.

Thanks for any help,
- emmanuel
thumbnail
Murat ÇOLAK, módosítva 13 év-val korábban

RE: Getting portlet session from its id

Junior Member Bejegyzések: 45 Csatlakozás dátuma: 2009.07.28. Legújabb bejegyzések
I think your code like this

PortletRequest realReq = (PortletRequest) request.getAttribute("javax.portlet.request");
User user = PortalUtil.getUser(realReq);
HttpSession session = PortalUtil.getHttpServletRequest(realReq).getSession();
thumbnail
Emmanuel Guiton, módosítva 13 év-val korábban

RE: Getting portlet session from its id

Junior Member Bejegyzések: 39 Csatlakozás dátuma: 2010.12.03. Legújabb bejegyzések
Thanks, but it does not work :
request.getAttribute("javax.portlet.request");
returns null.
thumbnail
David H Nebinger, módosítva 13 év-val korábban

RE: Getting portlet session from its id

Liferay Legend Bejegyzések: 14916 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Emmanuel Guiton:
I am trying to get the current user in the GWT servlet and I am stucked. I cannot get it directly, e.g.
final HttpServletRequest request = this.getThreadLocalRequest();
final User user = PortalUtil.getUser(request);
returns null;

Lots of folks seem to have issues w/ this, but it is due to not understanding session handling...

When you are in a different servlet than Liferay (your context root is separate), your servlet will have a different session than Liferay's and you will not have access to any session information from Liferay's session.

So the PortalUser.getUser() call will always return null because, at it's core, it is referencing session information that is not there.

I believe that the common answer given to this type of issue is to store the user id as a temporary cookie. You can then access the id across the session boundary.
thumbnail
Emmanuel Guiton, módosítva 13 év-val korábban

RE: Getting portlet session from its id

Junior Member Bejegyzések: 39 Csatlakozás dátuma: 2010.12.03. Legújabb bejegyzések
Well, I agree that the session content is not the same. And in fact, as I saw on some other post, the underlying object is not the same.

But the point is that the "sessions" are not so different since they share the same id.
So I get the correct id to identify the session I want, but I do not have any mean to fetch it. I feel as if I was looking for a building with a good map, a correct address, but ... no street.

As a workaround so far, I fetch the data I am interested in in the doView() method, set it in a global object, and pull the data from it in my GWT servlet code.
I prefer this solution to storing anything more on the client side, but it still feels somehow horrible ...

Any other suggestion ?
thumbnail
David H Nebinger, módosítva 13 év-val korábban

RE: Getting portlet session from its id

Liferay Legend Bejegyzések: 14916 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Emmanuel Guiton:
But the point is that the "sessions" are not so different since they share the same id.


The app container is still going to keep the session objects separate. And in general this is a really good thing from a security perspective; if I can somehow deploy my web app to your container I could then access everyone's session information, ...

Your app scope implementation would work. Depending upon how much control you have on the invocation of your servlet, you could also add a param to include in the call...
thumbnail
Murat ÇOLAK, módosítva 13 év-val korábban

RE: Getting portlet session from its id

Junior Member Bejegyzések: 45 Csatlakozás dátuma: 2009.07.28. Legújabb bejegyzések
You can use cookie
thumbnail
Emmanuel Guiton, módosítva 13 év-val korábban

RE: Getting portlet session from its id

Junior Member Bejegyzések: 39 Csatlakozás dátuma: 2010.12.03. Legújabb bejegyzések
You can use cookie

Isn't cookie a client side method ? emoticon
That is what I wanted to avoid.