我在Spring 5中构建了一个项目。然后我开始以角度(CORS)配置登录,但它只是在选项预检中给出了错误401。 如果你有什么可以帮助我的话,我会坚持这个。 后端项目:https://github.com/maiconpintoabreu/Spring5SecurityMongodbTest 感谢
@Order(4)
公共类WebSecurityConfiguration扩展了WebSecurityConfigurerAdapter {
...
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/**").hasAnyRole("ADMIN","USER")
.antMatchers(HttpMethod.OPTIONS, "**").permitAll()
.antMatchers("/resources/**").permitAll()
.anyRequest().authenticated().and()
.httpBasic().and().cors().and();
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
return source;
}
}