2013-04-06 205 views
1

當我做了如何在Spring Security 3.0.5中獲取所有應用程序的在線用戶?

org.springframework.security.core.userdetails.UserDetailsS​​ervice

的實施和使用語句

sessionRegistry.registerNewSession(user.getUsername() ,用戶);

內它

在成功認證之後,則

sessionRegistry.getAllPrincipals();

列表不爲空(但是當我從應用程序註銷時,會話仍然保留在列表中),否則此列表將爲空。我怎樣才能在sessionRegistry中自動進行會話註冊(以及在用戶註銷或會話過期期間註銷)?我的彈簧配置如下:

<sec:http auto-config="true" use-expressions="true" access-denied-page="/accessDenied.jsf"> 
    <sec:form-login login-page="/login.jsf" /> 
    <sec:session-management session-authentication-strategy-ref="sas" /> 
</sec:http> 

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

<bean id="scr" 
class="org.springframework.security.web.context.HttpSessionSecurityContextRepository" /> 

<bean id="smf" 
class="org.springframework.security.web.session.SessionManagementFilter"> 
<constructor-arg name="securityContextRepository" 
    ref="scr" /> 
<property name="sessionAuthenticationStrategy" 
    ref="sas" /> 
</bean> 

<bean id="sas" 
class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy"> 
<constructor-arg name="sessionRegistry" 
    ref="sessionRegistry" /> 
<property name="maximumSessions" value="10" /> 
</bean> 

回答

1

您很可能忘記了添加一個HttpSessionEventPublisher to your web.xml

另一種可能性是,有問題的主體還有其他會話仍處於活動狀態,這些會話尚未超時或已失效。您的最大會話值爲10.嘗試將其設置爲「1」,而不是進行測試。

此外,版本3.0.5已過時。您應該使用最新版本並及時瞭解補丁以避免漏洞。

+0

否我的web.xml中存在HttpSessionEventPublisher。其實我想讓併發seseseions但我認爲使用sessionRegistry獲得所有在線用戶的列表,我必須使用ConcurrentSessionControlStrategy!如果我的想法不是真的,那麼使用sessionRegistry的替代方法是什麼?在我的測試中,我從不同的瀏覽器登錄,然後打印當前的會話 – nazila 2013-04-06 14:56:54

相關問題