SpringBoot+SpringSecurity注销时报错404的两种解决方法


SpringBoot+SpringSecurity注销时报错404的两种解决方法

security的404问题

解决方案

方法一: 关闭csrf保护

在SpringSecurity配置内中,关闭csrf保护

   ...
   @Override
    protected void configure(HttpSecurity http) throws Exception {
        //关闭跨域访问,解决注销404问题
        http.csrf().disable();

    }

方法二:以post方式提交“注销请求”

SpringSecurity的注销配置

//注销  
http.logout().logoutUrl("/toLogout").logoutSuccessUrl("/toLogin").invalidateHttpSession(true);

所以,这里将/toLogout请求改为用表单以post方式提交。在此方法下,不用关闭SpringSecurity的csrf保护

<form th:action="@{/toLogout}" method="post">
	<input type="submit" value="注销"/>
</form>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM