亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用xml禁用Spring Security中的注銷確認?

如何使用xml禁用Spring Security中的注銷確認?

暮色呼如 2023-09-20 16:13:29
我已將 Spring security 從 4.x 更新到 5.x。現在,我遇到了 Spring security 要求用戶確認注銷的情況。有留言您確定要退出嗎?下面給出的圖像相同。我想去掉這一步。如何擺脫注銷確認?目標:我想注銷并重定向到我來自的頁面。security.xml:<beans:beans xmlns="http://www.springframework.org/schema/security"             xmlns:beans="http://www.springframework.org/schema/beans"             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"             xsi:schemaLocation="http://www.springframework.org/schema/beans                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd                http://www.springframework.org/schema/security                http://www.springframework.org/schema/security/spring-security-4.2.xsd">    <http auto-config="true" use-expressions="true">        <!-- isAnonymous() -->        <intercept-url pattern="/**/add/**" access="isAuthenticated()" />        <intercept-url pattern="/**/delete/**" access="isAuthenticated()" />        <intercept-url pattern="/**/update/**" access="isAuthenticated()" />    </http>    <authentication-manager>        <authentication-provider>            <user-service>                <user name="uzer64" password="{noop}123456" authorities="ROLE_USER" />                <user name="admin" password="{noop}admin" authorities="ROLE_ADMIN" />            </user-service>        </authentication-provider>    </authentication-manager></beans:beans>
查看完整描述

3 回答

?
慕村9548890

TA貢獻1884條經驗 獲得超4個贊

這是一個 CSRF 功能,可以避免來自其他站點的惡意 javascript 發起的注銷請求。

您的請求是GET: /logout,因此 Spring Security 希望通過用戶操作(例如單擊)來確認它。


所以要避免它。您的注銷請求應該POST包含有效的_csrf令牌。


您可以通過使用 spring 表單標簽和方法 post 來實現它,如下所示


<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

...

<form:form action="${pageContext.request.contextPath}/logout" 

           method="post" modelAttribute="AnyModelAttributePassedFromController">

    <form:button value="submit"> Logout</form:button>

</form:form>

...

或者


<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

...

<form:form action="${pageContext.request.contextPath}/logout" 

           method="post" modelAttribute="_csrf">

    <form:button value="submit"> Logout</form:button>

</form:form>

...


查看完整回答
反對 回復 2023-09-20
?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

@Override

    protected void configure(HttpSecurity http) throws Exception {

        http

            .logout()

                .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));

    }

這個對我有用。


查看完整回答
反對 回復 2023-09-20
?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

您可以嘗試以下方法:-

    <logout
    logout-success-url="/anonymous.html"
    logout-url="/perform_logout" />

您可以提及要重定向的網址。您還可以添加 delete-cookies="JSESSIONID"刪除cookie。


查看完整回答
反對 回復 2023-09-20
  • 3 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號