The LoginEvent is meant to perform actions when the credentials are submitted, so when your listener is called, the user might not yet have been authenticated. The login listener is usually used to perform authentication programmatically, not to handle post-authentication actions.
When using Spring Security, if you want to always redirect to a given page after login, you should use the FormLoginConfigurer in your configuration class and remove the login listener in the Vaadin view.
For example
http.formLogin(cfg -> cfg.successForwardUrl("/"))
or you can use a custom successHandler
By default, Vaadin defines a successHandler implementation that redirects to the protected URL that the user was trying to access or to the root path (/)
Nevertheless: I would expect Vaadin’s configurer to provide such hooks… it feels really weird to configure Vaadin and afterwards add a “form based authentication” just for the handlers
@knoobie you’re right! I completely missed that issue.
And, yeah, it’s also weird that we have loginView methods that take a logoutSuccessUrl but not a loginSuccessUrl. loginSuccessUrl should definitely be added to VaadinSecurityConfigurer.
The current workaround is to register a custom VaadinSavedRequestAwareAuthenticationSuccessHandler
VaadinSavedRequestAwareAuthenticationSuccessHandler successHandler = new VaadinSavedRequestAwareAuthenticationSuccessHandler();
successHandler.setDefaultTargetUrl("/main");
successHandler.setAlwaysUseDefaultTargetUrl(true);
http.setSharedObject(VaadinSavedRequestAwareAuthenticationSuccessHandler.class, successHandler);
http.with(vaadin(), c -> { ... });