So adding the
.antMatchers(HttpMethod.OPTIONS,"/path/to/allow").permitAll()//allow CORS option calls
line did solve the 401 response. I'm still have trouble with CORS though, it still somehow thinks it's invalid…
I added the following but it's still not working.. argh…
public class CorsFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
if (request.getHeader("Access-Control-Request-Method") != null
&& "OPTIONS".equals(request.getMethod())) {
// CORS "pre-flight" request
response.setHeader("Access-Control-Allow-Credentials",
"true");
response.setHeader("Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE");
response.setHeader("Access-Control-Allow-Headers",
"X-Requested-With,Origin,Content-Type, Accept, Authorization");
response.setHeader("Access-Control-Max-Age",
"100");
}
filterChain.doFilter(request, response);
}
}