spring security 403 error

前端 未结 4 1564
清歌不尽
清歌不尽 2020-12-07 22:38

I\'m trying to secure my website using Spring security following the guides on the web. So on my server side the WebSecurityConfigurerAdapter and controller looks like this<

4条回答
  •  臣服心动
    2020-12-07 23:19

    The issue may be related to CSRF or CORS Security Protection.

    • FOR CSRF: You can disable it if the application users did not use it from browsers.
    • For CORS: You can specify the origin and allow HTTP Methods.

    The below code disable CSRF and allow all origins and HTTP methods. so be aware when using it.

    @Configuration
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter  implements WebMvcConfigurer {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable();
        }
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedMethods("*");
        }
    
    }
    

提交回复
热议问题