Depends on how your login is implemented, but if you have a servlet filter based approach, it’s possible that the VaadinSession hasn’t been initialized yet when your login code is running, yes. Docs about the application lifecycle can be found here: https://vaadin.com/docs/latest/flow/advanced/application-lifecycle#application.lifecycle.session; note that you can e.g. add a listener for session initialization.
The UI lifecycle is bound to a single browser tab while the session is shared between all the tabs in a browser instance. You should see this easily by adding a debugger breakpoint or a log statement in e.g. setUserToSession and opening two tabs in the same brower to this app. Make sure there aren’t any cases where a user might gain elevated privileges by logging in from two different tabs.
Ah yeah indeed its called per browser tab, then its not a good solution. Where would it be the best place to add it to the session once when i user Spring Security? Before login is to early, after login is too late ;)
I will try to add this into the @Override public UserDetails loadUserByUsername(String customerNo) {} from UserDetailsService