Learn Liferay7/DXP Filter Hook in 10 Minutes

In my last post, I discussed about action hook. In this post, you will learn about filter hook in Liferay7/DXP.

Just a quick recap in case you have not read my previous post. Liferay provides mechanism to override behaviour for out-of-the-box features is called hook. Liferay supports following types of hook,

  • Struts Action Hook
  • Filter Hook
  • Jsp Hook
  • Language properties Hook
  • Model Listener hook
  • Service Wrapper Hook

After looking at above list of filters, you may have question that where filter hook is applicable in development?

Filter hook are used for intercepting HTTP request to execute piece of code before it reaches to execution logic. This is like HTTP Filter.

Following are the prerequisite to start with hook development in Liferay 7/DXP.


There is a difference in way to implement hook in Liferay 7/DXP compare to prior versions as DXP does not provides option for XML configurations. Now Let’s create Filter hook in liferay7/DXP using following steps,

  1. Create Liferay Workspace Project:

    To create a Liferay Workspace in IDE follow the following steps:

Select File menu → click New → select Liferay Workspace Project. Upon creation of the workspace, the structure should look like below:

  1. Create Module:

    Next step is to create a Liferay Module Project.

Open File menu → click New → select Liferay Module Project. Provide project name as ‘FilterHook’ and click on ‘Next’.

  1. Configure hook properties:

    Provide component name and package path for the filter class and click on Finish.

Now class FilterHook with package com.enprowess.filterclass is created in workspace module as follow,

  1. Implement Component:

    In class, you need to add following property inside @Component.

  1. Implement code:

    Please note that your filter class will extend BaseFilter class. You will need to override processFilter() method which will take parameters as HttpServletRequest request, HttpServletResponse response, FilterChain filterChain.Please see following piece of code.

Now, you have filter hook ready to deploy in Liferay.

We at EnProwess believes in sharing knowledge to help open source community to grow. In my next post, I will talk about JSP hook. Till then happy learning!

Blog by,

Maitrik Panchal.

Share it :

Leave a Reply

4 Comments on "Learn Liferay7/DXP Filter Hook in 10 Minutes"

Notify of
Sort by:   newest | oldest

Good post. I want to overwrite existed filter. How should I do?
For example, I found If I open AutoLogin Filter, it will afftect all portal, all urls. I want to make the affected scope smaller by changing url pattern. Is it possible?


i want to use filter in service wrapper class will you please guide me how can i use it.

  • Categories

  • Recent Comments

  • Recent Post

  • Tags