Fórum
Login struts action overriding
nithin varghese, modificado 10 Anos atrás.
Login struts action overriding
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Hi,
I'm facing an issue with struts overriding where I have over ridden login action by adding the below entries in liferay-hook.xml .
so when ever I'm logged in it will come to the processAction method in SerVicePreAction .
But every time it is executed it is giving only default user Name . ie 10158 . Its not showing the name of the user who has currently logged in. How to get that.? please provide any solution for this.
I'm facing an issue with struts overriding where I have over ridden login action by adding the below entries in liferay-hook.xml .
<hook>
<portal-properties>portal.properties</portal-properties>
<struts-action>
<struts-action-path>/login/login</struts-action-path>
<struts-action-impl>com.mypkg.ServicePreAction</struts-action-impl>
</struts-action>
</hook>
so when ever I'm logged in it will come to the processAction method in SerVicePreAction .
public class ServicePreAction extends BaseStrutsPortletAction {
public void processAction(StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
User user = themeDisplay.getUser();
System.out.println(user.getScreenName());
originalStrutsPortletAction.processAction(originalStrutsPortletAction,
portletConfig, actionRequest, actionResponse);
}
}
But every time it is executed it is giving only default user Name . ie 10158 . Its not showing the name of the user who has currently logged in. How to get that.? please provide any solution for this.
Apoorva Prakash, modificado 10 Anos atrás.
RE: Login struts action overriding
Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens Recentesnithin varghese:
Hi,
I'm facing an issue with struts overriding where I have over ridden login action by adding the below entries in liferay-hook.xml .<hook> <portal-properties>portal.properties</portal-properties> <struts-action> <struts-action-path>/login/login</struts-action-path> <struts-action-impl>com.mypkg.ServicePreAction</struts-action-impl> </struts-action> </hook>
so when ever I'm logged in it will come to the processAction method in SerVicePreAction .public class ServicePreAction extends BaseStrutsPortletAction { public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest .getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser(); System.out.println(user.getScreenName()); originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse); } }
But every time it is executed it is giving only default user Name . ie 10158 . Its not showing the name of the user who has currently logged in. How to get that.? please provide any solution for this.
Hi Nithin,
Some issues appears in your code in first look, however its not very clear by your post that what do you want achieve:
1. You should extend PortletAction if you want create a custom Login Action class.
2. You are putting the SOP statement in processAction which will be called only when the user will press the sign in button, you should try to use the same code in doView() as will.
HTH.
Thanks and Regards,
Apoorva Prakash
nithin varghese, modificado 10 Anos atrás.
RE: Login struts action overriding
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Hi apoorva , thanks for your reply. What I exactly needed is to execute a few actions based on the user logged in .For that I've overridden the login struts action. So every time the user logged in, I'm getting the call in the process action method in my custom class. My problem is that , the user which is obtained from the themedisplay is always same. 10158 ie, default user. irrespective of the user logged in liferay. Suppose a user 'ABCD' logs in , i should get user details of ABCD from theme display. But I'm not getting that. please give me a solution.
Apoorva Prakash, modificado 10 Anos atrás.
RE: Login struts action overriding
Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens Recentesnithin varghese:
Hi apoorva , thanks for your reply. What I exactly needed is to execute a few actions based on the user logged in .For that I've overridden the login struts action. So every time the user logged in, I'm getting the call in the process action method in my custom class. My problem is that , the user which is obtained from the themedisplay is always same. 10158 ie, default user. irrespective of the user logged in liferay. Suppose a user 'ABCD' logs in , i should get user details of ABCD from theme display. But I'm not getting that. please give me a solution.
HI NIthin,
If you just want to do something after logs in, then there is no need to modify the login action. The same you can achieve with the help of login.events.pre.
See this link.
HTH.
Thanks ans Regards,
Apoorva Prakash
nithin varghese, modificado 10 Anos atrás.
RE: Login struts action overriding
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Hi apoorva,
I have tried to create hook for portal event login.events.post..
and created a class LoginAction which extends com.liferay.portal.kernel.events.Action .and added below entries in portal.properties file.
and the LoginAction class is shown below.
In this scenario also whenever the user logged in it will come to the run method of the LoginAction class. but themedisplay from the httpServletRequest is null. so I'm not getting user details. Any other suggestions..?
I have tried to create hook for portal event login.events.post..
and created a class LoginAction which extends com.liferay.portal.kernel.events.Action .and added below entries in portal.properties file.
login.events.post=com.msat.usop.LoginAction
and the LoginAction class is shown below.
public class LoginAction extends Action {
public LoginAction() {
super();
}
@Override
public void run(HttpServletRequest arg0, HttpServletResponse arg1)
throws ActionException {
ThemeDisplay themeDisplay = (ThemeDisplay) arg0
.getAttribute(WebKeys.THEME_DISPLAY);
System.out.println(themeDisplay.getUserId());
}
}
In this scenario also whenever the user logged in it will come to the run method of the LoginAction class. but themedisplay from the httpServletRequest is null. so I'm not getting user details. Any other suggestions..?
Apoorva Prakash, modificado 10 Anos atrás.
RE: Login struts action overriding
Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens Recentesnithin varghese:
Hi apoorva,
I have tried to create hook for portal event login.events.post..
and created a class LoginAction which extends com.liferay.portal.kernel.events.Action .and added below entries in portal.properties file.login.events.post=com.msat.usop.LoginAction
and the LoginAction class is shown below.public class LoginAction extends Action { public LoginAction() { super(); } @Override public void run(HttpServletRequest arg0, HttpServletResponse arg1) throws ActionException { ThemeDisplay themeDisplay = (ThemeDisplay) arg0 .getAttribute(WebKeys.THEME_DISPLAY); System.out.println(themeDisplay.getUserId()); } }
In this scenario also whenever the user logged in it will come to the run method of the LoginAction class. but themedisplay from the httpServletRequest is null. so I'm not getting user details. Any other suggestions..?
Hi Nithin,
You should use the following:
User user = UserLocalServiceUtil.getUserById(Long.parseLong(request.getRemoteUser()));
HTH,
Thanks and Regards,
Apoorva Prakash
nithin varghese, modificado 10 Anos atrás.
RE: Login struts action overriding
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Thanks apoorva. It will help me to get User details, but it will not fulfill my requirement since I'm not getting themedisplay. . Based on user logged in I need to set layout and theme dynamically. If I've got themedisplay , I can do that. please give me a solution.
Apoorva Prakash, modificado 10 Anos atrás.
RE: Login struts action overriding
Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens Recentesnithin varghese:
Thanks apoorva. It will help me to get User details, but it will not fulfill my requirement since I'm not getting themedisplay. . Based on user logged in I need to set layout and theme dynamically. If I've got themedisplay , I can do that. please give me a solution.
Hi Nithin,
The following works for me very well in service preaction and postaction:
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
HTH.
Thanks and Regards,
Apoorva Prakash
nithin varghese, modificado 10 Anos atrás.
RE: Login struts action overriding
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Hi Apoorva ,
In the code ,
request is an object of HttpServletRequest , thats why I'm getting themedisplay as null. I couldn't find out any other reason. if it is an object of PortletRequest I could have get themedisplay. so is there any way to get PortletRequest from HttpServletRequest ?
In the code ,
ThemeDisplay themeDisplay = (ThemeDisplay) request
.getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
request is an object of HttpServletRequest , thats why I'm getting themedisplay as null. I couldn't find out any other reason. if it is an object of PortletRequest I could have get themedisplay. so is there any way to get PortletRequest from HttpServletRequest ?
Hitesh Methani, modificado 10 Anos atrás.
RE: Login struts action overriding
Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens Recentes
Hello nithin,
It is not possible to get portlet request from http request.
But you can get logged in user using httpservlet request by using following code.
PortalUtil.getUser(Request) .
HTH.
Thanks,
Hitesh Methani.
It is not possible to get portlet request from http request.
But you can get logged in user using httpservlet request by using following code.
PortalUtil.getUser(Request) .
HTH.
Thanks,
Hitesh Methani.
nithin varghese, modificado 10 Anos atrás.
RE: Login struts action overriding
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Hi Hitesh , thanks for your reply. I'm getting User Details .But what I need is ThemeDisplay or Layout once the user logged in. suggest me a solution.
Hitesh Methani, modificado 10 Anos atrás.
RE: Login struts action overriding
Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens Recentes
I dont think its possible to get themedisplay or layout object in service pre action hook.
Thanks,
Hitesh M
Thanks,
Hitesh M
Jitendra Rajput, modificado 10 Anos atrás.
RE: Login struts action overriding
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens RecentesHitesh Methani:
I dont think its possible to get themedisplay or layout object in service pre action hook.
Yes. It is possible . You can get themeDisplay similar way even with HTTPServletRequest. I am able to get this themeDisplay in my service pre -action an it is working for me.
Check if you are using correct class for WebKeys and ThemeDisplay.
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
Apoorva Prakash, modificado 10 Anos atrás.
RE: Login struts action overriding
Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens RecentesJitendra Rajput:
Hitesh Methani:I dont think its possible to get themedisplay or layout object in service pre action hook.
Yes. It is possible . You can get themeDisplay similar way even with HTTPServletRequest. I am able to get this themeDisplay in my service pre -action an it is working for me.
Check if you are using correct class for WebKeys and ThemeDisplay.
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
Yes Jitendra, you are absolutely correct... It works fine...
nithin varghese, modificado 10 Anos atrás.
RE: Login struts action overriding
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Hi all,
Still i didn't get themedisplay from :
So I've tried to print all the attributes available in the httpservlet request like :
It has printed 10 below attribute names:
it doesn't have THEME_DISPLAY as an attribute name. so I was getting a null. @Apoorva can you please reply me with all the attribute names available in your http servlet request.?
Still i didn't get themedisplay from :
ThemeDisplay themeDisplay = (ThemeDisplay) request
.getAttribute(WebKeys.THEME_DISPLAY);
So I've tried to print all the attributes available in the httpservlet request like :
Enumeration<string> attriNames = request.getAttributeNames();
while (attriNames.hasMoreElements()) {
System.out.println( attriNames.nextElement());
}
</string>
It has printed 10 below attribute names:
CURRENT_COMPLETE_URL
COMPANY_ID
com.liferay.portal.servlet.filters.strip.StripFilterSKIP_FILTER
VIRTUAL_HOST_LAYOUT_SET
CURRENT_URL
User-Agent
CTX
com.liferay.portal.servlet.filters.gzip.GZipFilterSKIP_FILTER
INVOKER_FILTER_URI
com.liferay.util.CookieUtil
it doesn't have THEME_DISPLAY as an attribute name. so I was getting a null. @Apoorva can you please reply me with all the attribute names available in your http servlet request.?
Hitesh Methani, modificado 10 Anos atrás.
RE: Login struts action overriding (Resposta)
Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens Recentes
Hello Jitendra and Apoorva,
I agree its possible in service pre action, it was my mistake to write service pre action hook there, actually if you see the code, Nitin is trying to access it in login post action, which is not possible.
Thanks,
Hitesh
I agree its possible in service pre action, it was my mistake to write service pre action hook there, actually if you see the code, Nitin is trying to access it in login post action, which is not possible.
Thanks,
Hitesh
Apoorva Prakash, modificado 10 Anos atrás.
RE: Login struts action overriding (Resposta)
Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens RecentesHitesh Methani:
Hello Jitendra and Apoorva,
I agree its possible in service pre action, it was my mistake to write service pre action hook there, actually if you see the code, Nitin is trying to access it in login post action, which is not possible.
Thanks,
Hitesh
Yes Hitesh, It might be a reason...
nithin varghese, modificado 10 Anos atrás.
RE: Login struts action overriding (Resposta)
New Member Postagens: 13 Data de Entrada: 02/05/13 Postagens Recentes
Thank you all...
Since login post action is not providing themedisplay , I've taken service pre action as you said.
and in the run method I'm checking the user signed or not. it resolved my issue.
Since login post action is not providing themedisplay , I've taken service pre action as you said.
and in the run method I'm checking the user signed or not. it resolved my issue.
public class ServicePreAction extends Action {
@Override
public void run(HttpServletRequest request, HttpServletResponse respond)
throws ActionException {
ThemeDisplay themeDisplay = (ThemeDisplay) request
.getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
if (themeDisplay.isSignedIn()) {
// code for login post action
}
}
}
Jitendra Rajput, modificado 10 Anos atrás.
RE: Login struts action overriding
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
Just to update you diff of both of this event. ServicePreAction will be invoked on each and every request while Login Post action will be invoked after login.
Moisés Belda, modificado 10 Anos atrás.
RE: Login struts action overriding
Junior Member Postagens: 75 Data de Entrada: 20/04/13 Postagens Recentes
Is there a way to get source Action type in custom ServicePreAction to filter only Login Actions?
Can I rewrite sitePath attribute to make redirection in custom ServicePreAction (not LoginPostAction or LoginPreAction)?
I need themeDisplay too (for redirect after login based in actual layout), and LoginPostAction themedisplay is null.....
Can I rewrite sitePath attribute to make redirection in custom ServicePreAction (not LoginPostAction or LoginPreAction)?
I need themeDisplay too (for redirect after login based in actual layout), and LoginPostAction themedisplay is null.....
Hitesh Methani, modificado 10 Anos atrás.
RE: Login struts action overriding
Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens RecentesMoisés Belda:
Is there a way to get source Action type in custom ServicePreAction to filter only Login Actions?
Can I rewrite sitePath attribute to make redirection in custom ServicePreAction (not LoginPostAction or LoginPreAction)?
I need themeDisplay too (for redirect after login based in actual layout), and LoginPostAction themedisplay is null.....
Hello Moisés Belda,
I am not sure, what exactly you are trying to achive, but if it is only landing page action you are worried about, you can use DefaultLandingPageAction.java in hook which is also a login post event.
Thanks,
Hitesh M