title: Enable CSRF prevention using Spring security through XML configuration
body: <p>I am using Spring 4.1.6 and spring-security 4.0.1 in my web application.
  I have gone through many posts enable csrf using spring security in my application. Still I do not found a solution. I am not getting the csrf token in my jsp. They are still null. My normal web MVC application is working fine, but having issues with setup of security.</p>
  
  <p>The following changes that I have done to enable security is</p>
  
  <p><strong>Added following jars:</strong>
  spring-security-core-4.0.1
  spring-security-web-4.0.1
  spring-security-taglibs-4.0.1
  spring-security-config-4.0.1</p>
  
  <p><strong>Added SecurityConfig class</strong></p>
  
  <pre><code>import org.apache.log4j.Logger;
  import org.springframework.context.annotation.Configuration;
  import  org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  
  @Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
      private Logger logger = Logger.getLogger(SecurityConfig.class);
  
      @Override
  protected void configure(HttpSecurity http) throws Exception {
  
      logger.debug("Inside configure method of SecurityConfig class....");
      http
              .authorizeRequests()
              .anyRequest().permitAll();
  }
  }    
  </code></pre>
  
  <p>Added this filter in web.xml</p>
  
  <p>
          springSecurityFilterChain
          org.springframework.web.filter.DelegatingFilterProxy
      </p>
  
  <pre><code>&lt;filter-mapping&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>Please help.</p>
  
  <p>I am getting exceptions like</p>
  
  <blockquote>
    <p>SEVERE: WebModule[/AG_INDREVIEW]PWC1270: Exception starting filter springSecurityFilterChain
    java.lang.InstantiationException</p>
    
    <p>WARNING: WEB9052: Unable to load class org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer, reason: java.lang.NoClassDefFoundError: org/springframework/web/WebApplicationInitializer</p>
  </blockquote>