title: spring security with angular2 giving 403 forbidden error only on POST,PUT and delete
body: <p>I have spring mvc(rest), spring security(4.x) and angular2 application. App is deployed in weblogic and it takes care of SAML authentication, so my app is just using authorization piece only. To do that we are using custom request header authentication filter where we validate custom request header and based on that loads user from db with granted authority. All this works fine. </p>
  
  <p>Now I am implementing CSRF protection where my server is adding CSRF token cookie and since angular2 is has out of the box support for this it is passing same cookie as x-xsrf-token on all subsequent requests. </p>
  
  <p>Problem starts here where all GET requests are working fine but when my app does POST or PUT or DELETE, it is getting 403 error. Comparing GET and POST request, I noticed that POST request does not have "Access-Control-Allow-Headers", so I am thinking that somehow my server has to expose this headers, so that browser can send X-XSRF-TOKEN for POST/PUT request.</p>
  
  <p>Same headers are present on GET request.</p>
  
  <p>Can anyone explain am I on the right track or not? If yes, then how can I expose this headers in spring secuirty or spring mvc for whole application?</p>
  
  <p>If not then what is causing this issue?</p>
  
  <p>My CORS config</p>
  
  <pre><code>&lt;filter&gt;
    &lt;filter-name&gt;cors&lt;/filter-name&gt;
    &lt;filter-class&gt;com.elm.mb.rest.filters.CORSFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
    &lt;filter-name&gt;cors&lt;/filter-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  
  @Override
  protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
      response.addHeader("Access-Control-Allow-Origin", "*");
  
      if (request.getHeader("Access-Control-Request-Method") != null &amp;&amp; "OPTIONS".equals(request.getMethod())) {
          LOG.trace("Sending Header....");
          // CORS "pre-flight" request
          response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
          response.addHeader("Access-Control-Allow-Headers", "Content-Type,X-XSRF-TOKEN");
          response.addHeader("Access-Control-Max-Age", "1");
      }
  
      filterChain.doFilter(request, response);
  }
  </code></pre>