Skip to content

Commit

Permalink
#2988 Fixed active sessions load in loggedUsers bean when tomcat sta…
Browse files Browse the repository at this point in the history
…rts:

 - user sessions initialize first;
 - check admin;
  • Loading branch information
Limraj committed Aug 21, 2024
1 parent b06c4a8 commit a0e635a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/com/serotonin/mango/MangoContextListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -198,8 +200,6 @@ private void initialized(ServletContextEvent evt) {

initSchedule();

sessionsInitialize(evt);

log.info("Scada-LTS context started");
}

Expand Down
11 changes: 10 additions & 1 deletion src/org/scada_lts/login/LoggedUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -155,4 +155,13 @@ private static void update(User user, Map<Integer, User> 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;
}
}

0 comments on commit a0e635a

Please sign in to comment.