Hello @trungdv
Something like that should work. You can register this SessionExtension in a Program Start:
import ch.ivyteam.di.restricted.DiCore;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.persistence.IPersistentTransaction;
import ch.ivyteam.ivy.persistence.PersistencyException;
import ch.ivyteam.ivy.security.ISecurityManager;
import ch.ivyteam.ivy.security.ISession;
import ch.ivyteam.ivy.security.ISessionExtension;
import ch.ivyteam.log.Logger;
public class TrackingSessionEvents {
public static void register()
{
DiCore.getGlobalInjector().getInstance(ISecurityManager.class).addSessionExtension(new MySessionExtension());
}
private static class MySessionExtension implements ISessionExtension
{
private Logger log;
public MySessionExtension() {
log = Ivy.log();
}
@Override
public void createSession(ISession session, IPersistentTransaction arg1) throws PersistencyException {
log.info("create session for: " + session.getSessionUser().getName());
}
@Override
public void destroySession(ISession session, IPersistentTransaction arg1) throws PersistencyException {
log.info("destroy session for: " + session.getSessionUser().getName());
}
@Override
public void logoutSession(ISession session, IPersistentTransaction arg1, long arg2) throws PersistencyException {
log.info("logout session for: " + session.getSessionUser().getName());
}
}
}
answered
16.04.2018 at 09:30
Alex Suter ♦♦
3.1k●12●22●47
accept rate:
84%