【问题标题】:How to get all application's online users in Spring Security 3.0.5?Spring Security 3.0.5 中如何获取所有应用的在线用户?
【发布时间】:2013-03-28 19:25:24
【问题描述】:

当我为

做一个实现时

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

并使用语句

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

认证成功后在里面,然后

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>

【问题讨论】:

    标签: session spring-security


    【解决方案1】:

    您很可能忘记添加HttpSessionEventPublisher to your web.xml

    另一种可能性是,有问题的委托人还有其他未超时或无效的会话仍然处于活动状态。您的最大会话值为 10。请尝试将其设置为“1”以进行测试。

    此外,版本 3.0.5 已过时。您应该使用最新版本并及时更新补丁以避免漏洞。

    【讨论】:

    • 我的 web.xml 中不存在 HttpSessionEventPublisher。实际上我想让并发会话,但我认为使用 sessionRegistry 来获取我必须使用 ConcurrentSessionControlStrategy 的所有在线用户的列表!如果我的想法不正确,使用 sessionRegistry 的替代方法是什么?在我的测试中,我确实从不同的浏览器登录,然后打印当前会话
    猜你喜欢
    • 2012-12-27
    • 1970-01-01
    • 2014-07-29
    • 2012-11-16
    • 2021-02-18
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2020-02-12
    相关资源
    最近更新 更多