【发布时间】:2013-10-01 02:56:17
【问题描述】:
使用带有异步支持的 Spring 3.2。在匿名 Callable 方法中,安全上下文会丢失一次
@RequestMapping(value = "/home", method = RequestMethod.GET)
public Callable<String> home(final Model model) {
return new Callable<String>() {
@Override
public String call() throws Exception {
model.addAttribute("homeService", homeService.findId(1));
return "home";
}
};
}
这是应用于 servlet-context.xml 内的 bean 的安全装饰器
<beans:bean id="homeService" class="example.service.HomeServiceImpl" scope="request">
<security:intercept-methods>
<security:protect access="ROLE_USER" method="find*"/>
</security:intercept-methods>
</beans:bean>
这是错误,因为安全上下文不存在:
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
【问题讨论】:
标签: spring spring-mvc asynchronous spring-security servlet-3.0