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,
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,
Select File menu → click New → select Liferay Workspace Project. Upon creation of the workspace, the structure should look like below:

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


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



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.
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?
Hi Ying.c.Wang,
There are 3 different possibilities and based on your requirement you can choose one of the following approach.
1. If you want to apply your custom logic to auto login of Liferay, you can implement it by following way
@Component(immediate = true)
public class MyAutoLogin implements Autologin {
}
2. You can create new filter for specific url as suggested in this blog but If you want to modify OOTB AutoLoginFilter provided by Liferay, you need to create EXT plugin. Till Liferay 7 GA4, there is no way to create EXT plugins but it is expected from Liferay7 GA5.
What we suggest here is to disable autologin filter by following entry in portal-ext.properties file
com.liferay.portal.servlet.filters.autologin.AutoLoginFilter=false
And then you can create your own filter with your own logic.
3. If you want to add some action which can be performed after login then you can create post login hook. you can take reference of post login hook from here.
http://www.enprowess.com/blogs/osgi-based-liferay-postloginaction/
i want to use filter in service wrapper class will you please guide me how can i use it.
Hi Manat,
Thank you for the comment.
Is it custom service wrapper class you have? If you can elaborate objective/requirement in detail I would be happy to help you.