Tag: 安全上下文

在父上下文中声明Spring Bean与子上下文

我有一个spring bean(dao)对象,我通过下面的xml在我的ServletContext中实例化: <bean id="userDao" class="com.company.dao.impl.UserDaoImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> 这个bean是在我的webapp-servlet.xml文件中声明的,并被我的应用程序在ServletContext中使用。 我也使用SpringSecurity。 这是我的理解,它运行在不同的上下文(SecurityContext)。 我的应用程序有一个webapp-security.xml,我实例化一个自定义身份validation提供程序。 我想使用我的应用程序中使用我的dao也做我的安全上下文中的用户查找,但是当我运行: <bean id="userAuthenticationProvider" class="com.company.security.UserAuthenticationProvider"> <property name="userDao" ref="userDao" /> </bean> 我得到的错误说,没有这样的bean“userDao”。 这个bean在我的其他上下文中声明的bean中自动assembly,但不在我的安全上下文中。 根据Spring文档,我相信web.xml中需要两个独立的上下文 <listener> <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.security.web.session.HttpSessionEventPublisher </listener-class> </listener> 所以我的问题是,我怎样才能访问我的我的SecurityContext中的我的ServletContext居住的DAO? 有我的道的范围修饰符,或者我可以以某种方式在我的身份validation提供程序在运行时获取ServletContext? 作为参考,这是我想如何在我的身份validation提供程序中使用它: public class UserAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { @Override protected UserDetails retrieveUser(String userName, UsernamePasswordAuthenticationToken authenticationToken) throws AuthenticationException { // […]