Hey,
I have a suggestion for an extension to VaadinSecurityConfigurer:
In the past, there have been occasional requests to use a custom AuthenticationSuccessHandler in a Vaadin security configuration. See
https://github.com/vaadin/flow/issues/18071
or
https://stackoverflow.com/questions/79808779/change-default-success-url-in-spring-security-using-vaadin-24
I always had this wish too. ![]()
Such an auth-success-handler can - for example - be derived from VaadinSavedRequestAwareAuthenticationSuccessHandler and contains additional custom instructions, such as:
- update last_login in database table user
- put username in logback MDC in order to include this username in every log message
etc.
Option a) was to use a shared object:
http.setSharedObject(VaadinSavedRequestAwareAuthenticationSuccessHandler.class, createSuccessHandler());
VaadinSavedRequestAwareAuthenticationSuccessHandler createSuccessHandler() {
return new MyAuthSucessHandler();
}
Option b) was to use an ApplicationEventListener for an InteractiveAuthenticationSuccessEvent
public ApplicationListener<InteractiveAuthenticationSuccessEvent> successHandler() {
return event -> {
//...
}
}
Of course, option c) would be much better, as it is based on the declarative approach of Spring Security and would enable something like this:
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.with(VaadinSecurityConfigurer.vaadin(), configurer -> {
// this already works ππ»
configurer.loginView(LoginView.class);
// this not yet ππ»
configurer.setAuthSuccessHandler(authSuccessHandler);
})
.build();
}
Perhaps it will make it into Vaadin 25.0.0. ![]()
Kind regards
Dominik