use of org.olat.core.util.SignOnOffEvent in project openolat by klemens.
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");
}
use of org.olat.core.util.SignOnOffEvent in project openolat by klemens.
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");
}
}
use of org.olat.core.util.SignOnOffEvent in project openolat by klemens.
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);
}
}
}
use of org.olat.core.util.SignOnOffEvent in project OpenOLAT by OpenOLAT.
the class UserSessionManager method signOn.
/**
* prior to calling this method, all instance vars must be set.
*/
public void signOn(UserSession usess) {
boolean isDebug = log.isDebug();
// fix a possible dead-lock see also OLAT-3390
synchronized (usess) {
if (isDebug)
log.debug("signOn() START");
if (usess.isAuthenticated()) {
throw new AssertException("sign on: already signed on!");
}
IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
Identity identity = identityEnvironment.getIdentity();
if (identity == null) {
throw new AssertException("identity is null in identityEnvironment!");
}
SessionInfo sessionInfo = usess.getSessionInfo();
if (sessionInfo == null) {
throw new AssertException("sessionInfo was null for identity " + identity);
}
usess.setAuthenticated(true);
if (sessionInfo.isWebDAV()) {
// load user prefs
usess.reloadPreferences();
// we're only adding this webdav session to the authUserSessions - not to the userNameToIdentity.
// userNameToIdentity is only needed for IM which can't do anything with a webdav session
authUserSessions.add(usess);
log.audit("Logged on [via webdav]: " + sessionInfo.toString());
} else {
UserSession invalidatedSession = null;
if (isDebug) {
log.debug("signOn() authUsersNamesOtherNodes.contains " + identity.getName() + ": " + authUsersNamesOtherNodes.contains(identity.getKey()));
}
// check if already a session exist for this user
if ((userNameToIdentity.contains(identity.getKey()) || userSessionCache.containsKey(identity.getKey())) && !sessionInfo.isWebDAV() && !sessionInfo.isREST() && !usess.getRoles().isGuestOnly()) {
log.info("Loggin-process II: User has already a session => signOffAndClear existing session");
invalidatedSession = getUserSessionForGui(identity.getKey());
// signOffAndClear does not remove the identity.getName().toLowerCase() from the userNameToIdentity
if (invalidatedSession != null) {
authUserSessions.remove(invalidatedSession);
}
}
authUserSessions.add(usess);
// characters -> map stores values as such
if (isDebug)
log.debug("signOn() adding to userNameToIdentity: " + identity.getName().toLowerCase());
userNameToIdentity.add(identity.getKey());
userSessionCache.put(identity.getKey(), new Integer(Settings.getNodeId()));
// reload user prefs
usess.reloadPreferences();
log.audit("Logged on: " + sessionInfo.toString());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, true), ORES_USERSESSION);
// check if a session from any browser was invalidated (IE has a cookie set per Browserinstance!!)
if (invalidatedSession != null || authUsersNamesOtherNodes.contains(identity.getKey())) {
// put flag killed-existing-session into session-store to show info-message 'only one session for each user' on user-home screen
usess.putEntry(STORE_KEY_KILLED_EXISTING_SESSION, Boolean.TRUE);
if (isDebug)
log.debug("signOn() removing from authUsersNamesOtherNodes: " + identity.getName());
authUsersNamesOtherNodes.remove(identity.getKey());
// OLAT-3381 & OLAT-3382
if (invalidatedSession != null) {
signOffAndClear(invalidatedSession);
}
}
if (isDebug)
log.debug("signOn() END");
}
// update logged in users counters
if (sessionInfo.isREST()) {
sessionCountRest.incrementAndGet();
} else if (sessionInfo.isWebDAV()) {
sessionCountDav.incrementAndGet();
} else {
sessionCountWeb.incrementAndGet();
}
}
}
use of org.olat.core.util.SignOnOffEvent in project openolat by klemens.
the class UserSessionManager method signOn.
/**
* prior to calling this method, all instance vars must be set.
*/
public void signOn(UserSession usess) {
boolean isDebug = log.isDebug();
// fix a possible dead-lock see also OLAT-3390
synchronized (usess) {
if (isDebug)
log.debug("signOn() START");
if (usess.isAuthenticated()) {
throw new AssertException("sign on: already signed on!");
}
IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
Identity identity = identityEnvironment.getIdentity();
if (identity == null) {
throw new AssertException("identity is null in identityEnvironment!");
}
SessionInfo sessionInfo = usess.getSessionInfo();
if (sessionInfo == null) {
throw new AssertException("sessionInfo was null for identity " + identity);
}
usess.setAuthenticated(true);
if (sessionInfo.isWebDAV()) {
// load user prefs
usess.reloadPreferences();
// we're only adding this webdav session to the authUserSessions - not to the userNameToIdentity.
// userNameToIdentity is only needed for IM which can't do anything with a webdav session
authUserSessions.add(usess);
log.audit("Logged on [via webdav]: " + sessionInfo.toString());
} else {
UserSession invalidatedSession = null;
if (isDebug) {
log.debug("signOn() authUsersNamesOtherNodes.contains " + identity.getName() + ": " + authUsersNamesOtherNodes.contains(identity.getKey()));
}
// check if already a session exist for this user
if ((userNameToIdentity.contains(identity.getKey()) || userSessionCache.containsKey(identity.getKey())) && !sessionInfo.isWebDAV() && !sessionInfo.isREST() && !usess.getRoles().isGuestOnly()) {
log.info("Loggin-process II: User has already a session => signOffAndClear existing session");
invalidatedSession = getUserSessionForGui(identity.getKey());
// signOffAndClear does not remove the identity.getName().toLowerCase() from the userNameToIdentity
if (invalidatedSession != null) {
authUserSessions.remove(invalidatedSession);
}
}
authUserSessions.add(usess);
// characters -> map stores values as such
if (isDebug)
log.debug("signOn() adding to userNameToIdentity: " + identity.getName().toLowerCase());
userNameToIdentity.add(identity.getKey());
userSessionCache.put(identity.getKey(), new Integer(Settings.getNodeId()));
// reload user prefs
usess.reloadPreferences();
log.audit("Logged on: " + sessionInfo.toString());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, true), ORES_USERSESSION);
// check if a session from any browser was invalidated (IE has a cookie set per Browserinstance!!)
if (invalidatedSession != null || authUsersNamesOtherNodes.contains(identity.getKey())) {
// put flag killed-existing-session into session-store to show info-message 'only one session for each user' on user-home screen
usess.putEntry(STORE_KEY_KILLED_EXISTING_SESSION, Boolean.TRUE);
if (isDebug)
log.debug("signOn() removing from authUsersNamesOtherNodes: " + identity.getName());
authUsersNamesOtherNodes.remove(identity.getKey());
// OLAT-3381 & OLAT-3382
if (invalidatedSession != null) {
signOffAndClear(invalidatedSession);
}
}
if (isDebug)
log.debug("signOn() END");
}
// update logged in users counters
if (sessionInfo.isREST()) {
sessionCountRest.incrementAndGet();
} else if (sessionInfo.isWebDAV()) {
sessionCountDav.incrementAndGet();
} else {
sessionCountWeb.incrementAndGet();
}
}
}
Aggregations