Perhaps there should not be a redirect, but simply a page display. Especially no settings, nothing, I use Java based configuration:
@Configuration @EnableWebSecurity public class Security extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/api/**").authenticated() .and() .exceptionHandling().accessDeniedPage("/error"); } } The / error page opens, everything is OK, access to all api / ** links is closed, but instead of a redirect to / error, I get the standard 403 Tomcat window.
@Controller public class Pages { @RequestMapping("/error") public String index() { return "error"; } } Moreover, if you specify the login page via .formLogin , then the redirect to the login page starts working. And if you specify my error in formLogin , everything will work. But not exceptionHandling .