簡體   English   中英

避免Spring應用程序在瀏覽器關閉時注銷

[英]Avoid Spring application log out on browser close

我有一個奇怪的問題,無法解決。

問題 :

我登錄到具有較長會話超時的Spring Web應用程序時,每當我退出瀏覽器然后重新打開它,訪問我的Web應用程序時,每次都會看到登錄頁面。

只要瀏覽器沒有關閉,它就可以正常工作。 我以為Chrome設置有問題,但是不是。 所有瀏覽器也會發生這種情況。

我的web.xml

    <session-config>
        <session-timeout>10000</session-timeout>
        <cookie-config>
            <name>myapp</name>
            <http-only>true</http-only>
        </cookie-config>
        <tracking-mode>COOKIE</tracking-mode>
    </session-config>

我的Spring Security配置:

    <security:http auto-config="true" use-expressions="true">
        <security:intercept-url pattern="/resources/**" access="permitAll" />
        <security:intercept-url pattern="/login" access="permitAll" />
        <security:intercept-url pattern="/login/forgot" access="permitAll" />
        <security:intercept-url pattern="/login/resetpassword" access="permitAll" />
        <security:intercept-url pattern="/home/admin/**" access="hasAnyRole('ROLE_admin', 'ROLE_manager')" />
        <security:intercept-url pattern="/**" access="hasAnyRole('ROLE_admin', 'ROLE_manager','ROLE_user')" />
        <security:form-login 
            login-page="/login" 
            login-processing-url="/login" 
            authentication-failure-handler-ref="authenticationFailureFilter" 
            authentication-success-handler-ref="authenticationSuccessHandler"  
            username-parameter="email" 
            password-parameter="password" />
        <!-- enable csrf protection -->
        <security:csrf/>

    </security:http>

我的web.xml或Spring Security是否有問題?

請設置Cookie的最大年齡屬性。

默認情況下,返回-1,這表示cookie將持續存在直到瀏覽器關閉。

Http Servlet Cookie的最大年齡

暫無
暫無

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

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