gpt4 book ai didi

java - spring security - 有没有办法在我的应用程序中获取 session 注册表(无需显式自定义并发过滤器)

转载 作者:IT老高 更新时间:2023-10-28 13:47:21 24 4
gpt4 key购买 nike

我指的是 this线程,并在 Rob Winch 的倒数第二篇文章中(Spring Security Lead),他提到我们可以访问 sessionRegisty :

<session-management>
<concurrency-control session-registry-alias="sessionRegistry"/>
</session-management>

因此,我注册了 HttpSessionEventPublisher过滤 web.xml并在我的 <http> 中指定上述设置部分。我不要添加这个:

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

在我的类里面,我像这样注入(inject) sessionRegistry 的一个实例:

@Autowired
private SessionRegistry sessionRegistry

这就是我试图找出用户 session 的方式:

List<SessionInformation> userSessions = sessionRegistry.getAllSessions(username,false);
for (SessionInformation userSession : userSessions){
userSession.expireNow();
}

主体是用户的用户名。调试后,sessionRegistry变量的principalssessionids变量为空。我在这里做错了什么,或者是krams's blog中提到的步骤吗? ,这样做的唯一方法?

最佳答案

你可以 Autowiring sessionRegistry。没有什么是错的。我用它来跟踪 SessionInformation 并为 UserPrincipal

注册 session

关于java - spring security - 有没有办法在我的应用程序中获取 session 注册表(无需显式自定义并发过滤器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11791154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com