I know that I can getAllSessions for user with current active session, and I know I can getAllPrincipals that will show all users with active sessions. But I want to know if it is possible to getAllSessions for a specific user. So say I am userA with current active session and I want to getAllPrincipals and then choose one of the principals and then getAllSessions for that specific principal. Is this possible? If so how?
You're talking about SessionRegistry
and in the API there is getAllSessions(Object principal, boolean includeExpiredSessions)
method you can use. For example:
List<Object> allPrincipals = getAllPrincipals();
Object principal = allPrincipals.get(0); // change this to way you want
List<SessionInformation> principalSessions = getAllSessions(principal, false);
Just remember that principal object can be anything, like User
or your own implementation, but it has to define equals()
and hashCode
properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.