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