Search code examples
liferayliferay-7

Liferay 7 Login Post Event can be set in portal-ext.properties?


Can setting login.events.post = com.custom.LoginPostAction in portal-ext.properties work i tried this way in liferay 7, its not working. How can we trigger the login post events in liferay 7.

liferay-hook.xml

<hook> <portal-properties>portal.properties</portal-properties> </hook>

portal.properties

login.events.post=com.test.action.LoginPostAction

I'm getting the below exception

Unable to load com.test.action.LoginPostAction with the portal class loader or the current context class loader java.lang.ClassNotFoundException: com.test.action.LoginPostAction from [Module "deployment.ROOT.war" from Service Module Loader] at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)


Solution

  • You'll now have Lifecycle Actions. Those are OSGi components that fire on the desired event. You can find a template (and some configuration options) in the blade sample repository

    To make this answer self-contained: Code now looks like this - look up the build instructions in the sample (and adapt from pre- to post-login)

    @Component(
        immediate = true, property = "key=login.events.pre",
        service = LifecycleAction.class
    )
    public class LoginPreAction implements LifecycleAction {
    
        @Override
        public void processLifecycleEvent(LifecycleEvent lifecycleEvent)
            throws ActionException {
    
            // Your code goes here
        }
    }
    

    In general, the plugin mechanism has changed dramatically between Liferay 6.x and 7.x. Typically you should migrate all your old customizations to OSGi - I'm wondering if the Upgrade Wizard within Liferay IDE takes care of some of that itself... it's been a long time since I've used it.