I call a HTTP post method first time, I catch an MissingCsrfTokenException because session is null, so I add bellow line to configuration
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
after the change, I try again but at the http method calling I catch org.springframework.security.web.csrf.InvalidCsrfTokenException: Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'. (Csrf protection is Disabled as below)
@Override
protected void configure(HttpSecurity http)
throws Exception {
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
.and()
.authorizeRequests()
.antMatchers(public_path)
.permitAll()
.anyRequest()
.hasAnyRole(required_role_for_all_request)
.and()
.httpBasic().disable()
.csrf().disable()
.logout().logoutUrl(logout_url)
.logoutSuccessHandler(this.customLogoutSuccessHandler)
.addLogoutHandler(this.customLogoutHandler)
.and().exceptionHandling()
.accessDeniedHandler(this.customAccessDeniedExceptionHandler);
if (!properties.getCorsRequired()) {
http.cors().configurationSource(corsConfigurationSource());
}
super.configure(http);
}
I noticed that it only happens on HTTP POST method calling