我似乎找不到如何在 Struts 操作中获取对 Spring Security (V3) SessionRegistry 的引用。
我已经在我的 web.xml 文件中配置了监听器:
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
而且我尝试使用@Autowired 注释将它带入一个 Action 中:
@Autowired
private SessionRegistry sessionRegistry;
@Override
public String execute() throws Exception {
numberOfUsersLoggedin= sessionRegistry.getAllPrincipals().size();
return SUCCESS;
}
public SessionRegistry getSessionRegistry() {
return sessionRegistry;
}
public void setSessionRegistry(SessionRegistry sessionRegistry) {
this.sessionRegistry = sessionRegistry;
}
http 配置如下所示:
<session-management invalid-session-url="/public/login.do?login_error=expired"
session-authentication-error-url="/public/login.do"
session-fixation-protection="newSession">
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/>
</session-management>
一般来说,我更愿意自己连接 Spring bean,但不确定如何使用命名空间公开它。每次执行操作时, session 注册表为空。
任何人都可以指出我在这里做错了什么,或者告诉我如何找到一个例子吗?
提前感谢任何/所有回复!
最佳答案
如果您通过命名空间配置 Spring Security,concurrency-control 标记的以下属性可用于访问 SystemRegistry:
- session 注册表别名。
- session-registry-ref.
官方文档对各个属性的描述:
session-registry-alias. It can also be useful to have a reference to the internal session registry for use in your own beans or an admin interface. You can expose the internal bean using the session-registry-alias attribute, giving it a name that you can use elsewhere in your configuration.
session-registry-ref. The user can supply their own SessionRegistry implementation using the session-registry-ref attribute. The other concurrent session control beans will be wired up to use it.
关于java - 我如何获得 Spring Security SessionRegistry?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3886256/