Issue with User Session Persistence in Vaadin with Spring Security

Hi everyone,

I’m developing a Vaadin Flow application with Spring Boot and Spring Security and I’m facing an issue with user sessions.

I’m using SecurityContextHolder to retrieve the currently logged-in user.

I’m also using VaadinSession to try and maintain the session state.

However, when I refresh the page, the user gets logged out.

I was expecting the session to persist across page refreshes. Could someone guide me on how to properly handle user sessions in Vaadin to keep users logged in after a page refresh?

Did you check that the JSESSION cookie is the same after a refresh? If yes: the http session did not terminate and it’s more like a problem in your code instead of the Vaadin(Http)Session.

If you use VaadinWebSecurity, it configures the SecurityContextHolder to use VaadinSession, not HttpSession. This means that VaadinSession deseriallzation needs to be performed before SpringSecurity in your filter chain.

1 Like

Can you explain more on that ?

I really can’t without knowing more details on your setup.

Here is my github repo

This is just a side observation. This storing of the user info in VaadinSession attribute is not necessary

As I pointed above VaadinWebSecurity will configure the SecurityContextHolder to use VaadinSession already.

1 Like

To access user information you can also inject into your view the AuthenticationContext object provided by Vaadin.