I'd like your help to get how implement this function: admin gets all logged in users using sessionRegistry.getAllPrincipals() and then can log off someone. I know how to log off current user (session.invalidate()), but have no idea how to force log out other users.
This code gets me all logged in users
public List<User> getAllLoggedInUsers() {
List<Object> principals = sessionRegistry.getAllPrincipals();
List<User> usersNamesList = new ArrayList<>();
for (Object principal : principals) {
if (principal instanceof org.springframework.security.core.userdetails.User) {
usersNamesList.add(dao.findByLogin(((org.springframework.security.core.userdetails.User) principal).getUsername()));
}
}
return usersNamesList;
}
Thanks a lot.
EDIT 1: I want next: admin chooses a user, bans it (change info in DB) and then if this user is active - log him off.