1

I'm using spring security in my project which is deployed in tomcat server.

I'm getting all logged in users using following method,

@Autowired
private SessionRegistry sessionRegistry;

public List<String> getAllActiveUsers() {
    String currentUsername = getCurrentUserName();
    return sessionRegistry.getAllPrincipals().stream()
            .filter(u -> !sessionRegistry.getAllSessions(u, false).isEmpty()
                    && !((User) u).getUsername().equals(currentUsername))
            .map(o -> ((User) o).getUsername())
            .collect(Collectors.toList());
}

Method works fine before the restart as expected. After I shutdown and restart tomcat login sessions are remaining fine since tomcat persists them while shutting down and restoring them in the start up. But when I call this getAllActiveUsers method it returns me a empty list. Seems like restored sessions are not getting added into the sessionRegistry. I will be very thankful if you could help me to resolve this.

  • Why do you think it is possible? Did you read it in any documentation? – dur Nov 25 '17 at 14:44
  • @dur I did some research and couldn't find it in any documentation. I was wondering whether there would be some work around to do this. Like "creating my own Java collection based active session store and add session while tomcat starts". But seems like it's not possible right? – Yasitha Thilakaratne Nov 25 '17 at 20:21
  • I think, you can do something by yourself, but I don't know a built-in way. – dur Nov 25 '17 at 21:14
  • thanks @dur. will see. need to investigate deeper. – Yasitha Thilakaratne Nov 25 '17 at 21:17

0 Answers0