Usually, you cannot cancel a user session right away when you change account information without resorting to a specific API, as the only way to access HttpSession is through the HttpServletRequest object.
Instead, you can cache the username in the store in memory and consult it either in the filter or in the regular AccessDecisionVoter . Using a flag in a user table is not really a great idea, since the flag is short-lived (it does not matter after the server is restarted), and it is better to avoid getting a database query for each query in performance.
There's a blog article about using custom voters for these kinds of things. This is deprecated, but the general approach sounds.
Another approach is to use the Spring Security SessionRegistry , which is part of the session management functionality. This is usually used to limit the number of sessions that a user can have, but can also be used to list the currently authenticated users , or to mark their session after expiration.
You might also get the idea of ββsimply reloading user privileges rather than completely logging them out.
Shaun the sheep
source share