I'm building a REST API with jax-rs and WildFly 10. Some of the endpoints are secured. I'm using FORM based authentication.
In my javascript code, I check the response of the AJAX
request, and if it is set to 401 Unauthorized
, I then present a login form to the user. When he fills it in, I POST the details to j_security_check
.
Running on localhost
this all works fine, but when the webserver and the REST server are on different machines, the browser denies the AJAX request due to cross-origin issues.
I understand CORS, so I added a CORS filter to my REST server that sets CORS headers for the GUI server. It all works fine, except for one small, but important detail: after the login has succeeded, the CORS filter does not fire for the j_security_check
response. No CORS headers are added and the browser can not read the response.
Apart from this one detail I have the whole setup working exactly like I want it.... But I have been struggling with this detail all night and I just can't get it to work.
I understand there are issues with trying to filter j_security_check
, but I know of no other ways to add CORS headers... So my question is:
How do I add CORS headers to the response for j_security_check
?
ContainerResponseFilter
. I’m able to add all the neededAccess-Control-Allow-XXX
headers to any response on the server side. But response to thej_security_check
request is an exception. Have you managed to find the solution? Thank in advance:). – Gree