I want to store the the user’s ID in a session variable to use across the application. I don’t see how I’d do that with the default security feature? It authenticates itself and I don’t know (if) there is a callback function or something? That we can use to do our house-keeping
Any help is deeply appreciated
You can use a
Filterfor this which checks if the user is logged in by container managed security (i.e.HttpServletRequest#getUserPrincipal()doesn’t returnnull) and then sets the session variable if not present.Basically:
However, maybe you don’t need to do it at all since it proves that you aren’t aware about
HttpServletRequest#getUserPrincipal(). It may namely already offer exactly the information you need. The login username (it may be the same as the user ID where you’re talking about) is available byPrincipal#getName().