Liferay Service Hook
Liferay Service Hook are used to override methods in the Liferay Service Layer. You can override the all methods defined {EntityName}ServiceWrapper.java classes, but you can not add new methods. You can add methods but those are not accessible through LocalServiceUtil.
As you all know, liferay-hook.xml file holds all hook configuration. below is sample config for Service Wrapper Hook:
<hook>
<service>
<service-type>com.liferay.portal.service.{Entity}LocalService</service-type>
<service-impl>com.javasavvy.hook.services.CustomUserLocalService</service-impl>
</service>
</hook>
- create user-service-hook plugin.
- Create package : com.javasavvy.hook.services
- Create HOOK config:
- Right click on project, click on New -> Liferay Hook Configuration
- Select Services and click Next
- Click on Add and Select UserLocalService
- Provide ClassName as CustomUserLocalService and package name
- Generated liferay-hook.xml file wiil be:
-
<hook> <service> <service-type>com.liferay.portal.service.UserLocalService</service-type> <service-impl>com.javasavvy.hook.services.CustomUserLocalService</service-impl> </service> </hook>
-
- open the CustomUserLocalService and override the method: authenticateByEmailAddress().
-
public class CustomUserLocalService extends UserLocalServiceWrapper { public CustomUserLocalService(UserLocalService userLocalService) { super(userLocalService); } @Override public int authenticateByEmailAddress(long companyId, String emailAddress, String password, Map<String, String[]> headerMap, Map<String, String[]> parameterMap, Map<String, Object> resultsMap) throws PortalException, SystemException { System.out.println("Custom Login Authentication is called"); return super.authenticateByEmailAddress(companyId, emailAddress, password, headerMap, parameterMap, resultsMap); } }
-
- Now deploy the Hook now