diff --git a/src/com/serotonin/mango/MangoContextListener.java b/src/com/serotonin/mango/MangoContextListener.java index 2cc950e03..48d8627c5 100644 --- a/src/com/serotonin/mango/MangoContextListener.java +++ b/src/com/serotonin/mango/MangoContextListener.java @@ -111,6 +111,8 @@ public void contextInitialized(ServletContextEvent evt) { private void initialized(ServletContextEvent evt) { log.info("Scada-LTS context starting at: " + Common.getStartupTime()); + sessionsInitialize(evt); + scriptContextInitialize(); // Get a handle on the context. @@ -198,8 +200,6 @@ private void initialized(ServletContextEvent evt) { initSchedule(); - sessionsInitialize(evt); - log.info("Scada-LTS context started"); } diff --git a/src/org/scada_lts/login/LoggedUsers.java b/src/org/scada_lts/login/LoggedUsers.java index 7d5f6f2a3..c4dccddb0 100644 --- a/src/org/scada_lts/login/LoggedUsers.java +++ b/src/org/scada_lts/login/LoggedUsers.java @@ -127,7 +127,7 @@ public void loadSessions(Session[] sessions) { if(authentication != null) { String username = authentication.getName(); User sessionUser = userService.getUser(username); - if (sessionUser != null) { + if (sessionUser != null && (!sessionUser.isAdmin() || isAdmin(authentication))) { int userId = sessionUser.getId(); loggedSessions.putIfAbsent(userId, new ArrayList<>()); loggedSessions.get(userId).add(httpSession); @@ -155,4 +155,13 @@ private static void update(User user, Map loggedUsers, } loggedUsers.put(user.getId(), user); } + + private static boolean isAdmin(Authentication authentication) { + for(GrantedAuthority authority: authentication.getAuthorities()) { + if("ROLE_ADMIN".equals(authority.getAuthority())) { + return true; + } + } + return false; + } }