I have built a project in spring 5. Then I started to configure the login in angular(CORS) but it just gives me the error 401 in the options preflight. I am stuck with this one, if you have something to help let me know. Backend project: https://github.com/maiconpintoabreu/Spring5SecurityMongodbTest Thanks
Fixed with @Order and Cors configuration
@Order(4)
public class WebSecurityConfiguration extends 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;
}
}