Hi all

Normally we use Ivy.session().loginSessionUser(userName, password) to login. And we have common modules to do common stuff like this (wrap by Ivy component).

My question is: Does ivy support a mechanism that we can subscribe this event and we'll be notified when a ivy user is logged in?

Thanks

asked 16.04 at 00:31

trungdv's gravatar image

trungdv
450648798
accept rate: 55%


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());
        }
    }

}
link

answered 16.04 at 09:30

Alex%20Suter's gravatar image

Alex Suter ♦♦
1.7k61934
accept rate: 82%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×95

Asked: 16.04 at 00:31

Seen: 163 times

Last updated: 16.04 at 09:30