title: Spring Security Ajax login
body: <p>I have implemented this security proccess in my project: 
  <a href="http://krams915.blogspot.com/2010/12/spring-security-mvc-integration_18.html" rel="noreferrer">Spring Security 3 - MVC Integration Tutorial (Part 2)</a>.</p>
  
  <p>My problem is that I need to turn it into an Ajax-based login.
  What do I need to do in order to make this XML suitable with just returning string/JSON to the client?
  I understand that the problem might be in the <code>form-login</code> tag.  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
                             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                             http://www.springframework.org/schema/security 
                             http://www.springframework.org/schema/security/spring-security-3.0.xsd"&gt;
  
      &lt;!-- This is where we configure Spring-Security  --&gt;
      &lt;http auto-config="true" use-expressions="true" access-denied-page="/Management/auth/denied" &gt;
  
          &lt;intercept-url pattern="/Management/auth/login" access="permitAll"/&gt;
          &lt;intercept-url pattern="/Management/main/admin" access="hasRole('ROLE_ADMIN')"/&gt;
          &lt;intercept-url pattern="/Management/main/common" access="hasRole('ROLE_USER')"/&gt;
  
          &lt;form-login 
                  login-page="/Management/auth/login" 
                  authentication-failure-url="/Management/auth/login?error=true" 
                  default-target-url="/Management/main/common"/&gt;
  
          &lt;logout 
                  invalidate-session="true" 
                  logout-success-url="/Management/auth/login" 
                  logout-url="/Management/auth/logout"/&gt;
  
      &lt;/http&gt;
  
      &lt;!-- Declare an authentication-manager to use a custom userDetailsService --&gt;
      &lt;authentication-manager&gt;
              &lt;authentication-provider user-service-ref="customUserDetailsService"&gt;
                      &lt;password-encoder ref="passwordEncoder"/&gt;
              &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
      &lt;!-- Use a Md5 encoder since the user's passwords are stored as Md5 in the database --&gt;
      &lt;beans:bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/&gt;
  
      &lt;!-- A custom service where Spring will retrieve users and their corresponding access levels  --&gt;
      &lt;beans:bean id="customUserDetailsService" class="com.affiliates.service.CustomUserDetailsService"/&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>