簡體   English   中英

彈簧FORM_LOGIN_FILTER是否支持ConcurrentSessionControl?

[英]Does spring FORM_LOGIN_FILTER support ConcurrentSessionControl?

我正在做一個基本的spring安全設置。 這是我的spring-security.xml配置:

<http auto-config='false' entry-point-ref="authenticationEntryPoint">
        <custom-filter position="FORM_LOGIN_FILTER" ref="authenticationFilter" />
        <logout delete-cookies="JSESSIONID" logout-success-url="/" />
        <!-- <session-management > <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" 
            expired-url="/"/> </session-management> -->
            <session-management session-authentication-strategy-ref="sas"/>
    </http>

    <beans:bean id="authenticationFilter" class="com.diners.security.AuthenticationFilter">
        <beans:property name="authenticationManager" ref="authenticationManager" />
    </beans:bean>

    <beans:bean id="authenticationEntryPoint"
        class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
        <beans:property name="loginFormUrl" value="/index.jsp" />
    </beans:bean>

    <beans:bean id="concurrencyFilter"
        class="org.springframework.security.web.session.ConcurrentSessionFilter">
        <beans:property name="sessionRegistry" ref="sessionRegistry" />
        <beans:property name="expiredUrl" value="/" />
    </beans:bean>
    <beans:bean id="sas"
        class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
        <beans:constructor-arg name="sessionRegistry"
            ref="sessionRegistry" />
        <beans:property name="maximumSessions" value="1" />
    </beans:bean>

    <beans:bean id="sessionRegistry"
        class="org.springframework.security.core.session.SessionRegistryImpl" />

    <authentication-manager alias="authenticationManager">
        <authentication-provider>
            <user-service>
                <user name="kalai"
                    password="test"
                    authorities="ROLE_ADMIN" />
                <user name="magesh"
                    password="test"
                    authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

我正在使用自定義表單登錄過濾器。 我想要登錄的並發控制,以便用戶一次只能有一個會話。 在當前會話期滿或手動注銷之前,他應該無法登錄其他瀏覽器。

有人指出,添加以下偵聽器將解決此問題。 所以我在web.xml中添加了以下內容

<listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener> 

但這也沒有幫助我。 然后,我在某些表單登錄過濾器中發現將不支持並發會話控制。

我需要實施任何東西嗎? 誰能對此提出建議,或者您可以提供替代要求? 我有一個自定義過濾器,用於在成功和失敗的身份驗證時提供json響應。

任何幫助之手將不勝感激。

是的,它支持。 將以下內容添加到您的authenticationFilter bean中

    <property name="sessionAuthenticationStrategy" ref="sas" />

暫無
暫無

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

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