Spring Boot: accessDeniedHandler does not work

前端 未结 4 953
北荒
北荒 2020-12-14 20:44

I\'ve got the following Spring Security configuration:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter          


        
4条回答
  •  鱼传尺愫
    2020-12-14 20:49

    The AccessDeniedHandler only applies to authenticated users. The default behaviour for unauthenticated users is to redirect to the login page (or whatever is appropriate for the authentication mechanism in use).

    If you want to change that you need to configure an AuthenticationEntryPoint, which is invoked when an unauthenticated user attempts to access a protected resource. You should be able to use

    http.exceptionHandling().authenticationEntryPoint(...)
    

    instead of what you have. For more details, check the API docs.

提交回复
热议问题