0

I have this in my server side code (spring-mvc):
@CrossOrigin(origins = "*") @Controller

Yet when I try to make a request using in Angular 4 I get the following error:

XMLHttpRequest cannot load http://localhost:8081/newProject/updateTaskRemarks?goalSectionId=1002&goalSectionSupRemarks=yo. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 403.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
HBK
  • 735
  • 1
  • 11
  • 29
  • Are there any other errors in your web console? – Gab Aug 30 '17 at 15:19
  • 1
    *“The response had HTTP status code 403”* indicates the real problem is an authentication failure. The only reason you’re seeing that CORS error message is because many servers typically don’t add the Access-Control-Allow-Origin header to error responses—instead they only add them to success responses (e.g., 200 OK). So the problem you need to figure out and solve is why you’re getting an authentication failure for your request. – sideshowbarker Aug 30 '17 at 22:43
  • @GabrieleB-David No other errors. – HBK Sep 01 '17 at 06:19
  • @sideshowbarker there is no authentication failure – HBK Sep 01 '17 at 06:20

1 Answers1

0

thanks for your responses. The error has been resolved by including the following line in the WebSecurityConfigurerAdapter: http.authorizeRequests().antMatchers("/").permitAll().and() .csrf().disable();

HBK
  • 735
  • 1
  • 11
  • 29