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.
In my application, there is custom SecurityConfig which extends WebSecurityConfigurerAdapter and has code something like this:
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);
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.
Any help?