How to check if anyone is logged in?

Hi,

How to check if anyone is logged in? Or to list currently logged in users?

Karolina

Hi Karolina,

the best we can do here is a list of recent requests that lists for each user when he was last seen:

import net.datenwerke.security.service.authenticator.*;
import net.datenwerke.security.service.usermanager.*;
import java.util.GregorianCalendar;
 
def uservice = GLOBALS.getRsService(UserManagerService.class);
def diff = 1000*60*60;
def now = new GregorianCalendar().getTimeInMillis();
GLOBALS.getRsService(AuthenticatorService.class).getLastRequests().collect({ key, value ->
    uservice.getNodeById(key)?.getUsername() + " " + ((now-value)/1000/60) + " minutes ago\n";
}).join();

Does that help?

Cheers,
Thorsten

Hi Thorsten,

Thanks, I will try it.
Last seen = last activity, including logging out?

Cheers,
Karolina

Hi Thorsten,

The script works :slight_smile:
Additionally, for my needs (i.e. to clearly see that no other user is currently logged in), I’ve made a dynamic list similar to the audit log report with the following query:

SELECT 
  rs_user.username as username,
  rs_audit_log_entry.action as action,
  MAX(rs_audit_log_entry.date_field) AS datetime
FROM
  rs_audit_log_entry
  INNER JOIN rs_user ON (rs_audit_log_entry.user_id = rs_user.id)
WHERE
  rs_audit_log_entry.action LIKE 'LOGIN' OR 
  rs_audit_log_entry.action LIKE 'LOGOUT'
GROUP BY
  rs_user.username,
  rs_audit_log_entry.action
ORDER BY
  datetime DESC

It looks like some logouts are not in the log, but the script and the report should work well together.

Cheers,
Karolina