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.