for (Iterator<UserSession> iter = authUserSessions.iterator(); iter.hasNext();) {
UserSession session = iter.next();
long lastAccessTime = 0;
String username = null;
InstantMessagingClient client = null;
boolean isWebDav = false;
try {
lastAccessTime = session.getSessionInfo().getLastClickTime();
username = session.getIdentity().getName();
isWebDav = session.getSessionInfo().isWebDAV();
} catch (Exception e) {
log.info("Tried to get LastAccessTime from session that became in the meantime invalid", e.toString());
}
if (!isWebDav) { // leave webdav sessions untouched
if (InstantMessagingModule.isEnabled()) {
// avoid reconnection of dead or duplicate sessions
ClientManager mgr = InstantMessagingModule.getAdapter().getClientManager();
if (username != null && mgr.hasActiveInstantMessagingClient(username)) client = mgr.getInstantMessagingClient(username);
if (log.isDebug()) {
if (client != null) log.debug("Fetched im client via mangager. Connections status is - connected=" + client.isConnected()
+ " for user: " + client.getUsername());
else log.debug("Could not fetch IM client for user: " + username);
}
}
if (session != null) {
if ((timeNow - lastAccessTime) > autoLogOutCutTime) {
try {
// brasato:::: since tomcat doesn't do this in its normal
// session invalidation process,
// (since polling), we must do it manually.
// But: it does not belong here (must work also without IM, but
// with polling)
// brasato:: alternative: instead of a job, generate a timer
// which rechecks if clicked within 5 mins ??
// TODO: that presence change stuff should also be moved to the
// IMManager...
// invalidation triggers dispose of controller chain and closes
// IM
// and removes IM client
try {
SessionInfo sessionInfo = session.getSessionInfo();
if (sessionInfo!=null) {
HttpSession session2 = sessionInfo.getSession();
if (session2!=null) {
session2.invalidate();
}
}
} catch (IllegalStateException ise) {
// ignore since session already closed by user, see javadoc:
// " Throws: java.lang.IllegalStateException - if this method is called on an already invalidated session"
}
log.audit("Automatically logged out idle user: " + username);
} catch (Exception e) {
log.warn("Error while automatically logging out user: " + username, e);
}
} else if ((timeNow - lastAccessTime) > idleWaitTime) {
/**
*
* user is back on track
* send presence message available to inform
*
*/
if (InstantMessagingModule.isEnabled()) {
if ((client != null && client.isConnected())
&& (client.getPresenceMode() == Presence.Mode.available || client.getPresenceMode() == Presence.Mode.chat)) {
client.sendPresenceAutoStatusIdle();
// inform the GUI
InstantMessagingModule.getAdapter().getClientManager().sendPresenceEvent(Presence.Type.available, username);
if (log.isDebug()) {
log.debug("change presence for user " + client.getUsername() + " to away.");
}
}
}
} else {
if (InstantMessagingModule.isEnabled()) {
/**
* uses makes a brake
* last access was more than five minutes ago
* so set instant messaging presence to away
*/
if ((client != null && client.isConnected())
&& (client.getPresenceMode() == Presence.Mode.away || client.getPresenceMode() == Presence.Mode.xa)) {
client.sendPresence(Presence.Type.available, null, 0, Presence.Mode.valueOf(client.getRecentPresenceStatusMode()));
// inform the GUI
InstantMessagingModule.getAdapter().getClientManager().sendPresenceEvent(Presence.Type.available, username);
if (log.isDebug()) {
log.debug("change presence for user " + client.getUsername() + " back to recent presence.");
}
}
// check if we can switch user back to available mode
}
}