use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class UserSessionManager method processSignOnOffEvent.
private void processSignOnOffEvent(SignOnOffEvent se) {
try {
boolean debug = log.isDebug();
if (debug)
log.debug("event() START");
if (debug)
log.debug("event() is SignOnOffEvent. isSignOn=" + se.isSignOn());
if (!se.isEventOnThisNode()) {
// - Single OLAT Instance is never passing by here.
if (se.isSignOn()) {
// -> remember other nodes logged usernames
if (debug)
log.debug("event() adding to authUsersNamesOtherNodes: " + se.getIdentityKey());
authUsersNamesOtherNodes.add(se.getIdentityKey());
UserSession usess = getUserSessionForGui(se.getIdentityKey());
if (usess != null && usess.getSessionInfo() != null && se.getIdentityKey().equals(usess.getSessionInfo().getIdentityKey()) && !usess.getSessionInfo().isWebDAV() && !usess.getRoles().isGuestOnly()) {
// if this listening UserSession instance is from the same user
// and it is not a WebDAV Session, and it is not GuestSession
// => log user off on this node
signOffAndClearWithout(usess);
usess.init();
}
} else {
// -> remove from other nodes logged on list.
if (debug)
log.debug("event() removing from authUsersNamesOtherNodes: " + se.getIdentityKey());
authUsersNamesOtherNodes.remove(se.getIdentityKey());
}
}
if (debug)
log.debug("event() END");
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class UserSessionManager method getUserSessionForGui.
/**
* Lookup non-webdav, non-REST UserSession for identity key.
* @param identityKey
* @return user-session or null when no session was founded.
*/
private UserSession getUserSessionForGui(Long identityKey) {
UserSession identitySession = null;
if (identityKey != null) {
// do not call from somewhere else then signOffAndClear!!
Optional<UserSession> optionalSession = authUserSessions.stream().filter(userSession -> {
Identity identity = userSession.getIdentity();
if (identity != null && identityKey.equals(identity.getKey()) && userSession.getSessionInfo() != null && !userSession.getSessionInfo().isWebDAV() && !userSession.getSessionInfo().isREST()) {
return true;
}
return false;
}).findFirst();
identitySession = optionalSession.isPresent() ? optionalSession.get() : null;
}
return identitySession;
}
use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class UserSessionManager method invalidateOldestSessions.
/**
* Invalidate a given number of oldest (last-click-time) sessions except admin-sessions.
* @param nbrSessions number of sessions whisch will be invalidated
* @return Number of invalidated sessions.
*/
public int invalidateOldestSessions(int nbrSessions) {
int invalidateCounter = 0;
// 1. Copy authUserSessions in sorted TreeMap
// This is the Comparator that will be used to sort the TreeSet:
Comparator<UserSession> sessionComparator = new Comparator<UserSession>() {
@Override
public int compare(UserSession o1, UserSession o2) {
Long long1 = new Long((o1).getSessionInfo().getLastClickTime());
Long long2 = new Long((o2).getSessionInfo().getLastClickTime());
return long1.compareTo(long2);
}
};
// clusterNOK ?? invalidate only locale sessions ?
TreeSet<UserSession> sortedSet = new TreeSet<UserSession>(sessionComparator);
sortedSet.addAll(authUserSessions);
int i = 0;
for (Iterator<UserSession> iterator = sortedSet.iterator(); iterator.hasNext() && i++ < nbrSessions; ) {
try {
UserSession userSession = iterator.next();
if (!userSession.getRoles().isOLATAdmin() && !userSession.getSessionInfo().isWebDAV()) {
internSignOffAndClear(userSession);
invalidateCounter++;
}
} catch (Throwable th) {
log.warn("Error signOffAndClear ", th);
}
}
return invalidateCounter;
}
use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class UserSessionManager method getUserSessionIfAlreadySet.
/**
* Return the UserSession of the given request if it is already set or null otherwise
* @param hreq
* @return
*/
public UserSession getUserSessionIfAlreadySet(HttpServletRequest hreq) {
HttpSession session = hreq.getSession(false);
if (session == null) {
return null;
}
UserSession us = (UserSession) session.getAttribute(USERSESSIONKEY);
setHttpSessionTimeout(session, us);
return us;
}
use of org.olat.core.util.UserSession in project OpenOLAT by OpenOLAT.
the class UserSessionManager method getUserSession.
/**
* @param session
* @return associated user session
*/
public UserSession getUserSession(HttpSession session) {
UserSession us = (UserSession) session.getAttribute(USERSESSIONKEY);
if (us == null) {
synchronized (session) {
// o_clusterOK by:fj
us = (UserSession) session.getAttribute(USERSESSIONKEY);
if (us == null) {
us = new UserSession();
// triggers the
session.setAttribute(USERSESSIONKEY, us);
// valueBoundEvent -> nothing
// more to do here
}
}
}
// set a possible changed session timeout interval
setHttpSessionTimeout(session, us);
return us;
}
Aggregations