掲示板

Getting portlet session from its id

thumbnail
13年前 に Emmanuel Guiton によって更新されました。

Getting portlet session from its id

Junior Member 投稿: 39 参加年月日: 10/12/03 最新の投稿
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
13年前 に Murat ÇOLAK によって更新されました。

RE: Getting portlet session from its id

Junior Member 投稿: 45 参加年月日: 09/07/28 最新の投稿
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
13年前 に Emmanuel Guiton によって更新されました。

RE: Getting portlet session from its id

Junior Member 投稿: 39 参加年月日: 10/12/03 最新の投稿
Thanks, but it does not work :
request.getAttribute("javax.portlet.request");
returns null.
thumbnail
13年前 に David H Nebinger によって更新されました。

RE: Getting portlet session from its id

Liferay Legend 投稿: 14915 参加年月日: 06/09/02 最新の投稿
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
13年前 に Emmanuel Guiton によって更新されました。

RE: Getting portlet session from its id

Junior Member 投稿: 39 参加年月日: 10/12/03 最新の投稿
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
13年前 に David H Nebinger によって更新されました。

RE: Getting portlet session from its id

Liferay Legend 投稿: 14915 参加年月日: 06/09/02 最新の投稿
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
13年前 に Murat ÇOLAK によって更新されました。

RE: Getting portlet session from its id

Junior Member 投稿: 45 参加年月日: 09/07/28 最新の投稿
You can use cookie
thumbnail
13年前 に Emmanuel Guiton によって更新されました。

RE: Getting portlet session from its id

Junior Member 投稿: 39 参加年月日: 10/12/03 最新の投稿
You can use cookie

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