留言板

Liferay DXP HttpSession issue

thumbnail
Ravi Darji,修改在7 年前。

Liferay DXP HttpSession issue

Junior Member 帖子: 56 加入日期: 14-5-14 最近的帖子
Hello Everyone,
I am using Liferay DXP sp 1, and i am facing session issues in it.
what i did is,
I have created hook for login post action and filter hook.

My requirement is like after login it should redirect on particular url and also I want to filter request before land on that url.

So I created class “CustomLoginAction.java” for login post action,
Summary of CustomLoginAction.java’s logic is,
- Changing redirection url based on which rolde is getting logged-in.(redirect=”/guest/site/home”)
- Setting values in HttpSession like (redirect,role,userid)

No when it will land on redirected url, I have applied one filter on that, using class CustomFilter.java.
Summary of CustomFilter.java’s logic is,
- Inside processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) method logic is available.
- Custom logic
- Getting values from session which will set in CusomLoginAction.java (like: redirect)

Now the issue what I am getting is,
- Not able to get session in customFilter.java class which is sated in CustomLoginAction.java class.
- Both class using HttpSession to set and get values.

My Analysys:
HttpSession is implementing many classes (like HttpSessionAdaptor, StandardSessionFacade and 5 to 6 more.)
In CustomLoginAction.java the class HttpSessionAdaptor is getting used to set session
While in CustomFilter.java class(in which I am getting session values), StandartSessionFacade.java is getting used
So I am getting null values.
Due to this I can not proceed further because in whole portal process of after login, I am using session values which is seted in loginpost action hook(CustomLoginAction.java).

Hope you understood the problem.

Help would be appreciated.

Thanks & Regards,
Ravi Darji
thumbnail
David H Nebinger,修改在7 年前。

RE: Liferay DXP HttpSession issue

Liferay Legend 帖子: 14915 加入日期: 06-9-2 最近的帖子
Filter ordering is important.

Is your custom filter executing before the auto login filter?
thumbnail
Ravi Darji,修改在7 年前。

RE: Liferay DXP HttpSession issue

Junior Member 帖子: 56 加入日期: 14-5-14 最近的帖子
Hi David,

I am not using auto login filter,

What i did is:
i have modified one mvcActionCommand for /login/login, and inside it i am setting values in httpSession.
and trying to get those values in customFilter.(/group/site_name/home)

Regards,
Ravi Darji
thumbnail
David H Nebinger,修改在7 年前。

RE: Liferay DXP HttpSession issue

Liferay Legend 帖子: 14915 加入日期: 06-9-2 最近的帖子
So you're not understanding the flow...

When you click on the "login" button, the request goes through the various defined filters including the auto login filter as well as your custom filter.

After all filters processed, MainServlet takes over and invokes the portlet lifecycle request, so the incoming action request will eventually route to your MVC action command override for the login.

So as you can see things are not calling in an order that will work for you.
thumbnail
Ravi Darji,修改在7 年前。

RE: Liferay DXP HttpSession issue

Junior Member 帖子: 56 加入日期: 14-5-14 最近的帖子
David H Nebinger:
Filter ordering is important.

Is your custom filter executing before the auto login filter?


So, David you mean to say, filter order will affecting session values?

Regards,
Ravi darji
thumbnail
David H Nebinger,修改在7 年前。

RE: Liferay DXP HttpSession issue

Liferay Legend 帖子: 14915 加入日期: 06-9-2 最近的帖子
No, but filter order will control what is available when.

If I have one class Foo that sets a session var and another class Bar that reads the session var, it only works if Foo is invoked Before Bar.

If Bar is called first, the session var will not be set. When Foo gets to set the var, doesn't really matter because Bar will not come along again during same request.
thumbnail
Ravi Darji,修改在7 年前。

RE: Liferay DXP HttpSession issue

Junior Member 帖子: 56 加入日期: 14-5-14 最近的帖子
If I have one class Foo that sets a session var and another class Bar that reads the session var, it only works if Foo is invoked Before Bar.


As you said in your example, i have debugged and Foo class is invoked before Bar.

Thanks & Regards,
Ravi Darji