Liferay 7 - custom LoginPreAction / LoginPostAction
Liferay 7 - custom Login Pre/Post Action
Overview
This article describes how to create custom post/pre login actions in Liferay 7+.
Module Creation
Create
service
Liferay module for the LoginPostAction
Sample configuration:
- package name:
com.lifedev.login.events
- service name:
CustomLoginPostAction
- module name:
login-post-action
Defining dependencies
Define dependencies in
build.gradle
file:dependencies { compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel" compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations" compileOnly group: "javax.servlet", name: "javax.servlet-api" }
Defining OSGi metadata
Define OSGi metadata in
bnd.bnd
, sample:Bundle-Name: LifeDev Login Post Action Bundle-SymbolicName: com.lifedev.login.events Bundle-Version: 1.0.0
LoginPostAction implementation
Implement
CustomLoginPostAction
, sample:@Component( immediate = true, property = "key=login.events.post", service = LifecycleAction.class ) public class CustomLoginPostAction implements LifecycleAction { @Override public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException { _log.info("CustomLoginPostAction Start."); HttpServletRequest request = lifecycleEvent.getRequest(); HttpServletResponse response = lifecycleEvent.getResponse(); HttpSession session = lifecycleEvent.getSession(); //todo: implement business-logic here _log.info("CustomLoginPostAction End."); } private static final Log _log = LogFactoryUtil.getLog(CustomLoginPostAction.class); }
- it should implement
LifecycleAction
interface; - define
property = "key=login.events.post"
for LoginPostAction (if you need LoginPreAction - set key tologin.events.pre
); lifecycleEvent
object contains information about request, response and session, which you can use for your business-logic.
Comments
Post a Comment