Liferay Service Hook

Liferay Service  Hook are used to override methods in the Liferay Service Layer. You can override the all methods defined {EntityName} 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:

  1. create user-service-hook plugin.
    • In IDE,File -> New -> Liferay Plugin Project
    • Select plugin type as “Hook” and click Finish
      Liferay Service Hook
  2. Create package :
  3. Create HOOK config:
    • Right click on project, click on  New -> Liferay Hook Configuration
    • Select Services and click NextLiferay Hooks Configuration
    • Click on Add and Select UserLocalService Service Hook tutorial
    • Provide ClassName as CustomUserLocalService and package name Custom User Local Service
  4. Generated liferay-hook.xml file wiil be:
    1. <hook>
  5. open the CustomUserLocalService  and override the method: authenticateByEmailAddress().
    1. public class CustomUserLocalService extends UserLocalServiceWrapper {
       public CustomUserLocalService(UserLocalService userLocalService) {
       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);
  6. Now deploy the Hook now


Download the Liferay ServiceWrapper Hook

Leave a Comment

Your email address will not be published. Required fields are marked *