events login Developer Legacy

How to listen login or logout events?

Question

How to enable the listening of Jahia Login/Logout system events?

Answer

The fireLoginEvent and fireLogoutEvent are enabled by default since Digital Factory 7.0.0.2 in the jahia.properties file.

The ApplicationListener interface can be sued to listen to these two events as mentioned in our below Tech wiki :

Here is an example of two classes implementing the ApplicationListener interface:

package org.jahia.modules;

import org.jahia.params.valves.LoginEngineAuthValveImpl.LoginEvent;
import org.springframework.context.ApplicationListener;

public class MyLoginListener implements ApplicationListener<LoginEvent> {

    @Override
    public void onApplicationEvent(LoginEvent e) {
        System.out.println("Test onApplicationEvent (loginEvent)");
    }
}
package org.jahia.modules;

import org.jahia.bin.Logout.LogoutEvent;
import org.springframework.context.ApplicationListener;

public class MyLogoutListener implements ApplicationListener<LogoutEvent> {

    @Override
    public void onApplicationEvent(LogoutEvent e) {
        System.out.println("Test onApplicationEvent (logoutEvent)");
    }
}