从jaas LoginModule访问spring上下文

Die*_*ego 5 java spring spring-security jaas

我已经实现了Jaas登录模块,以便执行身份验证.我必须访问数据库以检索此模块中的用户/传递信息.

在同一个项目中,存在一些DAO bean的实现,但是不可能从jaas登录模块访问Spring上下文来检索DAO bean.

¿有人可以帮我吗?

我正在使用Spring Security将Jaas集成到我的应用程序中.

Pau*_*ire 1

如果您有权访问 LoginModule,只需为 LoginModule 添加接口 ApplicationContextAware 和 bean 定义即可。当应用程序启动时,上下文将在模块内可用。

public class LoginModule implements ApplicationContextAware {
    private ApplicationContext applicationContext;
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    } 
}
Run Code Online (Sandbox Code Playgroud)

接口的Javadoc: http://static.springsource.org/spring/docs/3.0.5.RELEASE/api/org/springframework/context/ApplicationContextAware.html