迟到总比没有好。Spring Boot为您默认了许多安全组件,包括CSRF保护。要做的事情之一是强制POST注销,请参阅此处:http ://docs.spring.io/spring- security/site/docs/3.2.4.RELEASE/reference/htmlsingle/#csrf- logout
如此一来,您可以使用以下方式覆盖此内容:
http.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().fullyAuthenticated()
.and()
.formLogin().loginPage("/login").failureUrl("/login?error").permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login");
最后一行很重要。