title: Spring Security login with a rest web service
body: <p>I have a SpringMVC web application that needs to authenticate to a RESTful web service using Spring Security.And i need to access this same application through a rest client.</p>
  
  <p>Here is What I need to implement</p>
  
  <p><strong>The accept header is application/json(For a java rest client )</strong></p>
  
  <ul>
  <li><p>After a successful login, It will be sent a token(Or sessionId) to rest client in the format of json</p></li>
  <li><p>After a login failure,It will be sent error message in the format of json.</p></li>
  </ul>
  
  <p><strong>For a web request</strong></p>
  
  <ul>
  <li><p>After a successful login,It will be redirecting to a success jsp page.</p></li>
  <li><p>After a login failure,It will be sent error message to the same loin page. </p></li>
  </ul>
  
  <p>How can i do this with spring mvc and spring security?.I have very less time to do this,any one please give me an example with spring-security.xml.</p>
  
  <p>Thanks</p>