In my setup I have a service behind a zuul gatway, configured with Spring Security; my client is a simple website performing an AJAX-request to the gateway.
I placed the CrossOrigin-Annotation on the endpoint in the service controller, so performing a request directly to the service passes, pointing the request to the gateway currently ends up in a 401 error in my OPTIONS-request.
It seems like the request with the Authorization Header doesn't reach Spring Security, as this header isn't allowed right now.
Currently I extend the WebSecurityConfigurerAdapter to permit all Options-requests.
EDIT: Question: How do I configure Spring Security to don't require authentication for OPTIONS-requests?
EDIT2: I created a GIST with the relevant code:
- Client:
hello.js
,index.html
- Gateway:
WebSecurityonfig.java
,SimpleCORSFilter.java
,GatewayApp.java
- Service:
ContactController.java
EDIT2: After gathering more information about OPTIONS-Preflight and Spring (Security) it seems like the problem comes from Spring Security.
We use a bearer token to authorize the clients, so the browser sends an OPTIONS-Preflight request to the server. The server is secured by Spring Security, which doesn't find a valid authorization header and therefore returns with 401-unauthorized