如何使用xml禁用Spring Security中的注销确认?

我已将 Spring security 从 4.x 更新到 5.x。现在,我遇到了 Spring security 要求用户确认注销的情况。有留言

您确定要退出吗?

下面给出的图像相同。

https://img4.mukewang.com/650aa9d100012a3f03410136.jpg

我想去掉这一步。如何摆脱注销确认?


目标:我想注销并重定向到我来自的页面。


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>


暮色呼如
浏览 83回答 3
3回答

慕村9548890

这是一个 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"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;method="post" modelAttribute="AnyModelAttributePassedFromController">&nbsp; &nbsp; <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"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;method="post" modelAttribute="_csrf">&nbsp; &nbsp; <form:button value="submit"> Logout</form:button></form:form>...

GCT1015

@Override&nbsp; &nbsp; protected void configure(HttpSecurity http) throws Exception {&nbsp; &nbsp; &nbsp; &nbsp; http&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .logout()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));&nbsp; &nbsp; }这个对我有用。

HUWWW

您可以尝试以下方法:-&nbsp;&nbsp;&nbsp;&nbsp;<logout &nbsp;&nbsp;&nbsp;&nbsp;logout-success-url="/anonymous.html" &nbsp;&nbsp;&nbsp;&nbsp;logout-url="/perform_logout"&nbsp;/>您可以提及要重定向的网址。您还可以添加&nbsp;delete-cookies="JSESSIONID"删除cookie。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java