title: How to disable csrf checks for integration tests in springboot
body: <p>I want to disable csrf when doing integration tests for my springboot application. I have already tried security.enable-csrf=false but that doesn't seem to have any effect. I have also tried passing csrf token in my tests via SecurityMockMvcRequestPostProcessors.csrf method but to no avail.</p>
  
  <p>In my application, there is custom SecurityConfig which extends WebSecurityConfigurerAdapter and has code something like this:</p>
  
  <pre><code>http
  .csrf()                   .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
  .and()
  .authorizeRequests()
  .antMatchers(LOGIN_URL).permitAll()
  .antMatchers("/api/v1/forgotpwd").permitAll()
  .antMatchers("/api/v1/changepwd").permitAll()
  .antMatchers("/api/v1/isLoggedIn").permitAll()
  .antMatchers("/api/**").authenticated()
  .and()
  .logout().logoutUrl("/api/v1/logout").deleteCookies("JSESSIONID").invalidateHttpSession(true)
  .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler())
  .and()
  .addFilter(jsonUsernamePasswordAuthenticationFilter())
  .addFilterAfter(new MDCEmailSetterFilter(),JsonUsernamePasswordAuthenticationFilter.class);
  </code></pre>
  
  <p>If I set http.csrf().disable(), my tests work and csrf token authentication failure does not happen otherwise it throws 403 with message that csrf token cannot be validated.</p>
  
  <p>Any help?</p>