I wonder if, with Spring Security, I can validate the user sessions, allowing only one browser tab open. Is it possible?
I would also like to know if I can do it, wh
I have recently implemented a solution to multiple tabs/windows using Spring Security. For successful login I use `LoginSucessHandler`` and set an unique window name in session. On the main template page I have setup a window name and on each page load verify window name with session's window name, if it is not the same then redirect to the error page.
Below are configurations and code:
@Service
public class LoginSucessHandler extends
SavedRequestAwareAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws ServletException, IOException {
User user = (User) authentication.getPrincipal();
String windowName = user.getUsername() + new Date().getTime();
HttpSession session = request.getSession();
session.setAttribute("windowName", windowName);
session.setAttribute("windowNameToSet", windowName);
super.onAuthenticationSuccess(request, response, authentication);
}
}
Main template or header page:
For security context:
Just make sure that on login.jsp above JavaScript is not included.