I recently upgraded to spring boot 3 in an application with Thymeleaf, and my custom 403 pages are no longer working.
Prior to the upgrade, I believe this line was key:
http.exceptionHandling().defaultAuthenticationEntryPointFor(new Http403ForbiddenEntryPoint(), new AntPathRequestMatcher("/**"));
Since the upgrade, when I'm not authenticated and try to access a restricted page, I just get this default error screen. This my security filter chain.
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeHttpRequests(requests -> requests
.requestMatchers("/",
"/login",
"/css/**",
"/js/**",
"/images/**",
"/static/favicon.ico",
"/favicon.ico",
"/fullscreen").permitAll()
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/login")
.permitAll()
)
.logout(logout -> logout
.logoutSuccessUrl("/logout-success")
.permitAll())
.exceptionHandling()
.defaultAuthenticationEntryPointFor(new Http403ForbiddenEntryPoint(), new AntPathRequestMatcher("/**"));
return http.build();
When logged in, my 404 and 500 error pages work as expected. I think there is something missing in the way I setup the security filter chain that is preventing this custom 403 error page from working. I couldn't find any resources on how to achieve this with spring boot 3. Any suggestions?