We need a functionality of killing a specific session (by session ID) from some kind of an admin panel.
I attempted using the following approach:
public static void killSession(String sid) {
HttpSessionContext sc = FacesUtil.getSession().getSessionContext();
HttpSession session=sc.getSession(sid);
session.invalidate();
}
However
- HttpSessionContext, and getSessionContext() and
getSession(sessionId) methods of a session are all deprecated (for seemingly paranoid security reasons) - The above code also gets a null session when invoked in an ApplicationScoped JSF managed bean
I’m seeking an alternative way of achieving the functionality.
Yes, you can’t invalidate
sessionfrom anothersessiondue to security reasons. What you can do is to manually store allsessionsin somestatic attributeavailable to admin. So user logs in, you add him and hissessionto this attribute (usually aMap/HashMapwith user as akeyandsessionasvalue).Look at my older answer here and you will get an idea.