1. Create Liferay Plugin project of type Hook
The first step is you have to create Liferay Plugin Project of type hook. Follow the post
https://proliferay.com/basics-liferay-hook-development/
2. Create new class CustomPreLoginAction
This is the class we will call as Custom Action. The content of the class should be like this
package com.proliferay.demo; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.liferay.portal.kernel.events.Action; import com.liferay.portal.kernel.events.ActionException; /** * * @author Hamidul Islam * */ public class CustomPreLoginAction extends Action{ @Override public void run(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ActionException { /** * Write your custom code here */ System.out.println("Invoking this line before Login"); } }
Note 1: If your Custom Action needs http servlet request and response extends the class com.liferay.portal.kernel.events.Action
Note 2: If your Custom Action does not require any request response object then extends the class com.liferay.portal.struts.SimpleAction
Note 3: Both com.liferay.portal.kernel.events.Action and com.liferay.portal.struts.SimpleAction are abstract class. We must add unimplemented method in our Custom Action.
Note 4: In run method write your custom code.
3. Tell Liferay that CustomPreLoginAction is the pre login action
This is simply done by adding below in our portal.properties
#Tue Dec 09 12:39:53 IST 2014 login.events.pre=com.proliferay.demo.CustomPreLoginAction
4. Yo have to tell Liferay where the portal.properties exist
This is done by
<?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> <portal-properties>portal.properties</portal-properties> </hook>
“Look the source code for details.
This is all about creating Custom Action by Hook. Deploy the hook. Before log in you will see the message
// System.out.println(“Invoking this line before Login“);
As mentioned in our custom action.