Angular 6 + Spring框架5 + Spring安全性

时间:2018-05-31 21:58:46

标签: angular spring-boot spring-security oauth-2.0

我在Spring 5中构建了一个项目。然后我开始以角度(CORS)配置登录,但它只是在选项预检中给出了错误401。 如果你有什么可以帮助我的话,我会坚持这个。 后端项目:https://github.com/maiconpintoabreu/Spring5SecurityMongodbTest 感谢

使用@Order和Cors配置

进行了修复
@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;
}

}

0 个答案:

没有答案