使用带有异步支持的 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";
}
};
}
这是应用于 bean 内部的安全装饰器servlet-context.xml
<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