Custom authentication success handler

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. :slight_smile:

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. :smiley:

Kind regards
Dominik

cough Redirect after successful login - #4 by marcoc_753

yep, this link should also be mentioned.
But the solution mentioned there can’t extend the auth success handler with additional functionalities … can only be used between the existing … guard rails