How to Hook Login Events in Liferay 7 ?
In this tutorial we are going to learn how we can hook the Login POST and PRE actions in liferay 7. To hook the post login or pre login event we need to use the liferay's com.liferay.portal.kernel.events.LifecycleAction class to process the events.
As we know that everything in liferay 7 is a component and we need to define this too as a component using the @Component annotation. In the component we need to define the LifecycleAction.class as a service. So the final @Component setup will look like this.
For Post Login Event we need to setup the @Component like this -:
@Component(
immediate = true, property = {"key=login.events.post"},
service = LifecycleAction.class
)
For Pre Login Event we need to setup the @Component like this -:
@Component(
immediate = true, property = {"key=login.events.pre"},
service = LifecycleAction.class
)
In both of the cases we need to implement the method processLifecycleEvent(LifecycleEvent lifecycleEvent) .
So below is the code snippet for both of the events.
Code for LoginPostAction
Code for LoginPreAction
For Post Login Event we need to setup the @Component like this -:
@Component(
immediate = true, property = {"key=login.events.post"},
service = LifecycleAction.class
)
For Pre Login Event we need to setup the @Component like this -:
@Component(
immediate = true, property = {"key=login.events.pre"},
service = LifecycleAction.class
)
So below is the code snippet for both of the events.
Code for LoginPostAction
Code for LoginPreAction
how to create post logout hook ?
ReplyDelete