我如何获得 Spring Security SessionRegistry? [英] How do I get the Spring Security SessionRegistry?

查看:153
本文介绍了我如何获得 Spring Security SessionRegistry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到如何在 Struts 操作中获取对 Spring Security (V3) SessionRegistry 的引用.

I can't seem to find how to get a reference to the Spring Security (V3) SessionRegistry inside of a Struts action.

我已经在我的 web.xml 文件中配置了监听器:

I've configured the listener inside of my web.xml file:

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

并且我尝试使用@Autowired 注释将其带入操作:

And I've tried to use the @Autowired annotation to bring it into an 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 配置如下所示:

The http configuration looks like this:

    <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,但不确定如何使用命名空间公开它.每次执行动作时,会话注册表为空.

Generally I am more comfortable wiring the Spring bean myself, but not sure how this is exposed using the namespace. Each time the action executes, the session registry is null.

谁能指出我在这里做错了什么,或者告诉我一个例子的方法?

Can anyone point out what I am doing wrong here, or show me the way to an example?

预先感谢您的任何/所有回复!

Thanks in advance for any/all replies!

推荐答案

不确定您是否参考过 会话管理 部分.它有一个结合命名空间和自定义 bean 的片段.

Not sure if you have referred to Session Management section in Spring Security reference documentation. It has a snippet combining namespace and custom beans.

这篇关于我如何获得 Spring Security SessionRegistry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆