Hi all,
I know I wrote a few minutes ago, but please believe me when I tell you that I have been working on this bug (Server connection lost, trying to reconnect… / Handshake failure, Unexpected Redirect 302) for 2 months. Finally, I was able to fix it.
Just for information, we use Vaadin 14.4.7, Spring Boot 2.3.4, Spring Boot Starter Security and keycloak 12.0.1. It was a mess at the beginning, configuring keycloak and vaadin. But at the end, with this configuration I was able to let it run together.
The other code that are not present here, has not been changed.
@Override
protected void configure (HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.anonymous()
.disable()
.requestCache()
.requestCache(requestCache())
.and()
.sessionManagement()
.sessionAuthenticationStrategy(sessionAuthenticationStrategy())
.and()
.addFilterBefore(keycloakPreAuthActionsFilter(), LogoutFilter.class)
.addFilterBefore(keycloakAuthenticationProcessingFilter(), LogoutFilter.class)
.addFilterAfter(keycloakSecurityContextRequestFilter(), SecurityContextHolderAwareRequestFilter.class)
.addFilterAfter(keycloakAuthenticatedActionsRequestFilter(), KeycloakSecurityContextRequestFilter.class)
.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint())
.and()
.logout()
.addLogoutHandler(keycloakLogoutHandler)
.logoutUrl("/sso/logout")
.logoutSuccessUrl("/")
.and()
.authorizeRequests()
.requestMatchers(SecurityUtils::isFrameworkInternalRequest)
.permitAll()
.anyRequest()
.authenticated();
}
@Override
public void configure (WebSecurity web) {
web
.ignoring()
.antMatchers(
"/VAADIN/**",
"/vaadinServlet/**",
"/vaadinServlet/UIDL/**",
"/vaadinServlet/HEARTBEAT/**",
"/favicon.ico",
"/robots.txt",
"/manifest.webmanifest",
"/sw.js",
"/offline.html",
"/icons/**",
"/images/**",
"/styles/**",
"/h2-console/**");
}
I commented in the configure (WebSecurity web) method that holds all ignoring paths for the authentication and added /vaadinServlet/** to it. Then I removed from the method configure (HttpSecurity http) the whole stack of the antMatcher().permitAll() that I have set in the configure (WebSecurity web) method.
In keycloak I have enabled the Service Accounts. See the attachment. However, I have no idea if this also helped to fix the error. :-).
That’s it.
Regarding the /vaadinServlet addition to the path after a re-login, I have to test if with this fix this issue also has been resolved.
For the moment on the local environment it seems like that, But I have to test it on our test environment. I will keep you up to date.
I hope I could help someone with this experience.
Best Regards
Simone
