title: spring security + angularjs ajax post
body: <p>I'm just implemented the Spring Security to my project. 
  I'm enabled CSRF.
  The problem is - that i think all the POST requests to REST API(Spring) is now blocked by spring security i think.</p>
  
  <p>This is my <strong>Spring Security config</strong></p>
  
  <pre><code>&lt;context:annotation-config/&gt;
  
  &lt;!-- enable use-expressions --&gt;
  &lt;http auto-config="true" use-expressions="true"&gt;
      &lt;headers&gt;
          &lt;cache-control /&gt;
      &lt;/headers&gt;
  
      &lt;intercept-url pattern="/maps/api/admin**" access="hasRole('ROLE_ADMIN')"/&gt;
      &lt;intercept-url pattern="/user**" access="hasRole('ROLE_USER')"/&gt;
  
      &lt;!-- access denied page --&gt;
      &lt;access-denied-handler error-page="/403"/&gt;
  
      &lt;form-login
              login-processing-url="/login/processing"
              login-page="/user-login"
              default-target-url="/"
              authentication-failure-url="/user-login"
              username-parameter="username"
              password-parameter="password"
              authentication-success-handler-ref="successHandler"
              authentication-failure-handler-ref="failureHandler"/&gt;
      &lt;logout logout-success-url="/maps/api/user-login?logout"  delete-cookies="JSESSIONID"/&gt;
      &lt;!-- enable csrf protection --&gt;
      &lt;csrf/&gt;
  &lt;/http&gt;
  </code></pre>
  
  <p>i have a custom <strong>authentication success handlers</strong> and POST for authentication works well.</p>
  
  <p>This is how i sent my POST for authentication (in Angular)</p>
  
  <pre><code>var req = {
      method: 'POST',
      url: '/login/processing',
      headers: {
          'Content-Type': "application/x-www-form-urlencoded",
          'Upgrade-Insecure-Requests': "1",
          'X-CSRF-TOKEN': $('input[name="_csrf"]').val()
      },
      data: $(obj.target).serialize()
  }
  
  $http(req)
      .success(function(data, status, headers, config){
         blab bla bla
      })
      .error(function(data){
          alert( "Exception details: " + JSON.stringify({data: data}));
      });
  </code></pre>
  
  <p>This is the example of other POST request i sending to retrieve a data from Spring REST API Controller:</p>
  
  <pre><code>    var formData = {
          "username" : $scope.registerUser.email,
          "password" : $scope.registerUser.password
      };
      var req = {
          method: 'POST',
          url: '/maps/api/user/register',
          headers: {
              'X-CSRF-TOKEN': $('input[name="_csrf"]').val(),
              //'Content-Type': "application/x-www-form-urlencoded"
              'Content-Type': 'application/json'
          },
          data: formData
      }
      $http(req)
          .success(function(data, status, headers, config){
              blaaaaaaaa
          })
          .error(function(data, status, headers, config){
              alert( "Exception details: " + JSON.stringify({data: data}));
          });
  </code></pre>
  
  <p>and getting this error:</p>
  
  <pre><code>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
  </code></pre>
  
  <p>but actually i got                 <code>'Content-Type': 'application/json'</code>
  as "accept" headers, and the controller also returns a JSON object.</p>
  
  <p>Can anyone help?</p>