簡體   English   中英

Spring安全性注銷轉到j_spring_security_logout

[英]Spring security logout goes to j_spring_security_logout

在我的Web應用程序中,當我嘗試注銷時,它將轉到j_spring_security_logout而不是給定的頁面。 在我的spring-security.xml頁面中,我添加了

<logout logout-success-url="/login" delete-cookies="JSESSIONID" />

問題是,當我使用spring security 3.1.4.RELEASE版本時,此方法較早起作用 現在我正在使用3.2.2.RELEASE

我也嘗試了以下方法。 沒工作

<logout logout-url="/logout" delete-cookies="JSESSIONID" />

spring-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.xsd">

<http auto-config='true'>
    <intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/**" access="ROLE_USER" />
    <form-login login-page="/login" default-target-url="/transaction-view"
        always-use-default-target="true" authentication-failure-url="/loginfailed" />
    <logout logout-url="/logout" logout-success-url="/login.jsp" delete-cookies="JSESSIONID" />
    <session-management invalid-session-url="/invalidSession.htm">
        <concurrency-control max-sessions="1"
            error-if-maximum-exceeded="true" /> <!--this will throw error to second login attempt -->
    </session-management>
    <!-- <custom-filter before="FORM_LOGIN_FILTER" ref="myFilter" /> -->
    <csrf />
</http>

<beans:bean id="customSecurityService"
    class="com.fg.monitoringtool.web.security.SecurityService"></beans:bean>
<beans:bean id="passwordEncoder"
    class="com.fg.monitoringtool.web.security.PasswordEncoderMD5"></beans:bean>


<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="customSecurityService">
        <password-encoder ref="passwordEncoder">
        </password-encoder>
    </authentication-provider>

</authentication-manager>

提前致謝。

啟用S​​pring Security CSRF保護后,必須使用POST注銷:

<c:url var="logoutUrl" value="/logout"/>
<form action="${logoutUrl}" method="post">
  <input type="submit" value="Log out" />
  <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>

使用默認注銷URL的更好方法是

<c:url var="logoutUrl" value="j_spring_security_logout"/>
<form action="${logoutUrl}" method="post">
  <input type="submit" value="Log out" />
  <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM