我有以下春季安全配置:春季启动:accessDeniedHandler不起作用
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/api/private/**", "/app/**").authenticated();
http.csrf().disable();
http.logout().logoutSuccessUrl("/");
http.exceptionHandling().accessDeniedPage("/403"); //.accessDeniedHandler(accessDeniedHandler);
}
}
我期待下面的逻辑:没有authenitcated用户会被重定向到/403
。而不是Spring显示默认的Tomcat 403页面。我也尝试过自定义accessDeniedHandler
,但没有取得任何成功。
如何在访问失败时实现自定义逻辑?