We can override Login Struts action by using Hook.
In the below example we are overriding struts action "/login/login". When a user login in Liferay "com.liferay.portlet.login.action.LoginAction" is the action class that calls.
Follow the below steps to perform the change of Struts Action:
- Create Liferay Plugin Project of type Hook.
- Write the below code in liferay-hook.xml to override Login Struts action
<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">
<hook>
<struts-action>
<struts-action-path>/login/login</struts-action-path>
<struts-action-impl>com.evon.action.CustomLoginAction</struts-action-impl>
</struts-action>
</hook>
- package com.evon.action;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.liferay.portal.kernel.struts.BaseStrutsPortletAction;
import com.liferay.portal.kernel.struts.StrutsPortletAction;
public class CustomLoginAction extends BaseStrutsPortletAction{
@Override
public void processAction(StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {
/**
* This is the custom process action
* Once you try to login this method will be invoked
* We can write our own logic here
* Invoke the original struts action at the end
*/
System.out.println("in Custom login........................");
originalStrutsPortletAction.processAction(
originalStrutsPortletAction, portletConfig, actionRequest,
actionResponse);
}
public String render(
StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse)
throws Exception {
return originalStrutsPortletAction.render(
null, portletConfig, renderRequest, renderResponse);
}
}
- Deploy the Hook and try to login, this will invoke method of CustomLoginAction class instead of default one.
0 Comment(s)