• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

origin 'null' has been blocked by CORS policy

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,

I am getting this error: origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am traversing from Angular 4 to Back end having Spring boot, And getting the above error.

Please see detailed error here:


This is the error of CORS Filter blocked my request.

I am also passing token along with request, as shown below.



Let me if any other information required. Please get me a solution for it.

Thanks,
Sunil Chauhan
 
Saloon Keeper
Posts: 10308
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is because your AJAX request is redirected. During a redirect, the Origin is set to 'null', and the final destination of your request will then reject the request because you're not allowed to make cross-origin AJAX requests.

You must make sure the user is logged in before you make the AJAX request to avoid being redirected.
 
SunilK Chauhan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right dear. Seems like call is being redirected to login page again even after successful login. But I didn't understand why?

Actually I am performing the sso login from my system to another system. So this is happening.

I don't know how to handle the situation. Can you please guide me?
 
SunilK Chauhan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing i want to tell you that, getting token from the server, I am calling my back end having spring boot framework to authorize the user.

And at that time this error is generated. So, can you please guide me how to handle it?
 
Stephan van Hulst
Saloon Keeper
Posts: 10308
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The redirect happens because Spring seems to think you're not logged in when performing an AJAX request. How did you set up Spring? Where do you store tokens from the identity provider that handles SSO?
 
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this filter implementation

 
SunilK Chauhan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,

I have applied the same code for CORSFilter to my existing code but now getting the different error.



It is saying status '0'. Can you please check it ?
 
Dhiraj Ray
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's now something related to your internet/intranet connection
 
SunilK Chauhan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But after changing the corsfilter code why it still gives me an error of http response?

Even in the internet also, I didn't find any solution for it.

One more thing, can you please tell me how to debug it? So that I can find the exact cause of the issue?

Or may be some other thing as solution we can apply?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!