Search in sources :

Example 1 with SignOnOffEvent

use of org.olat.core.util.SignOnOffEvent in project OpenOLAT by OpenOLAT.

the class UserSessionManager method internSignOffAndClear.

private void internSignOffAndClear(UserSession usess) {
    boolean isDebug = log.isDebug();
    if (isDebug)
        log.debug("signOffAndClear() START");
    signOffAndClearWithout(usess);
    // handle safely
    try {
        if (usess.isAuthenticated()) {
            SessionInfo sessionInfo = usess.getSessionInfo();
            IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
            Identity identity = identityEnvironment.getIdentity();
            log.audit("Logged off: " + sessionInfo);
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, false), ORES_USERSESSION);
            if (isDebug)
                log.debug("signOffAndClear() deregistering usersession from eventbus, id=" + sessionInfo);
            // fxdiff FXOLAT-231: event on GUI Preferences extern changes
            OLATResourceable ores = OresHelper.createOLATResourceableInstance(Preferences.class, identity.getKey());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().deregisterFor(usess, ores);
        }
    } catch (Exception e) {
        log.error("exception in signOffAndClear: while sending signonoffevent!", e);
    }
    // clear all instance variables, set authenticated to false
    usess.init();
    if (isDebug)
        log.debug("signOffAndClear() END");
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SessionInfo(org.olat.core.util.SessionInfo) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) AssertException(org.olat.core.logging.AssertException)

Example 2 with SignOnOffEvent

use of org.olat.core.util.SignOnOffEvent in project OpenOLAT by OpenOLAT.

the class UserSessionManager method event.

/**
 * only for SignOffEvents
 * - Usersession keeps book about usernames
 * - WindowManager responsible to dispose controller chain
 * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
 */
@Override
public void event(Event event) {
    if (event instanceof SignOnOffEvent) {
        SignOnOffEvent se = (SignOnOffEvent) event;
        processSignOnOffEvent(se);
    }
}
Also used : SignOnOffEvent(org.olat.core.util.SignOnOffEvent)

Example 3 with SignOnOffEvent

use of org.olat.core.util.SignOnOffEvent in project OpenOLAT by OpenOLAT.

the class ClusterLocker method event.

/**
 * receives all sign on / sign off events so it can release locks of users
 * which have or are logged off
 *
 * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
 */
@Override
public void event(Event event) {
    SignOnOffEvent se = (SignOnOffEvent) event;
    if (!se.isSignOn() && se.isEventOnThisNode()) {
        // it is a "logout" event - we are only interested in logout events
        // and it is from our VM => only release all locks from within one VM
        Long identKey = se.getIdentityKey();
        // since the lock is reentrant, a lock could be freed while a session still is in a locked workflow (2x lock and then once freed)
        try {
            clusterLockManager.releaseAllLocksFor(identKey);
            DBFactory.getInstance().commit();
        } catch (DBRuntimeException dbEx) {
            log.warn("releaseAllLocksFor failed, close session and try it again for identName=" + identKey);
            // TODO: 2010-04-23 Transactions [eglis]: OLAT-4318: this rollback has possibly unwanted
            // side effects, as it rolls back any changes with this transaction during this
            // event handling. Nicer would be to be done in the outmost-possible place, e.g. dofire()
            DBFactory.getInstance().rollbackAndCloseSession();
            // try again with new db-session
            log.info("try again to release all locks for identName=" + identKey);
            clusterLockManager.releaseAllLocksFor(identKey);
            log.info("Done, released all locks for identName=" + identKey);
        }
    }
}
Also used : DBRuntimeException(org.olat.core.logging.DBRuntimeException) SignOnOffEvent(org.olat.core.util.SignOnOffEvent)

Example 4 with SignOnOffEvent

use of org.olat.core.util.SignOnOffEvent in project OpenOLAT by OpenOLAT.

the class LockTest method testSaveEvent.

@Test
public void testSaveEvent() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("lock-save-event-");
    dbInstance.closeSession();
    log.info("Created identity=" + identity);
    // The group has no creation date -> commit will fail
    GroupImpl entry = new GroupImpl();
    entry.setName("bar");
    try {
        dbInstance.saveObject(entry);
        dbInstance.commit();
        fail("Should generate an error");
    } catch (DBRuntimeException dre) {
        log.info("DB connection is in error-state");
    }
    // DB transaction must be in error state for this test
    try {
        Locker locker = clusterCoordinator.getLocker();
        assertTrue(locker instanceof ClusterLocker);
        log.info("ClusterLocker created");
        Event event = new SignOnOffEvent(identity, false);
        log.info("START locker.event(event)");
        ((ClusterLocker) locker).event(event);
        log.info("DONE locker.event(event)");
    } catch (Exception ex) {
        log.error("", ex);
        fail("BLOCKER : ClusterLocker.event is not error-safe, db exception could happen and de-register event-listener");
    }
}
Also used : Locker(org.olat.core.util.coordinate.Locker) DBRuntimeException(org.olat.core.logging.DBRuntimeException) GroupImpl(org.olat.basesecurity.model.GroupImpl) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) Event(org.olat.core.gui.control.Event) Identity(org.olat.core.id.Identity) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 5 with SignOnOffEvent

use of org.olat.core.util.SignOnOffEvent in project openolat by klemens.

the class UserSessionManager method event.

/**
 * only for SignOffEvents
 * - Usersession keeps book about usernames
 * - WindowManager responsible to dispose controller chain
 * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
 */
@Override
public void event(Event event) {
    if (event instanceof SignOnOffEvent) {
        SignOnOffEvent se = (SignOnOffEvent) event;
        processSignOnOffEvent(se);
    }
}
Also used : SignOnOffEvent(org.olat.core.util.SignOnOffEvent)

Aggregations

SignOnOffEvent (org.olat.core.util.SignOnOffEvent)10 Identity (org.olat.core.id.Identity)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 AssertException (org.olat.core.logging.AssertException)4 DBRuntimeException (org.olat.core.logging.DBRuntimeException)4 SessionInfo (org.olat.core.util.SessionInfo)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 GroupImpl (org.olat.basesecurity.model.GroupImpl)2 Event (org.olat.core.gui.control.Event)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 UserSession (org.olat.core.util.UserSession)2 Locker (org.olat.core.util.coordinate.Locker)2