【发布时间】:2017-04-12 08:27:23
【问题描述】:
我有一个 Spring MVC 控制器,并希望使用 Spring Method Security 来保护它。
在以下示例中它可以工作 - @RequestMapping和@PreAuthorizeannotate 相同的方法:
@Controller
public class MyController {
@RequestMapping(value = "/test", method = {RequestMethod.POST, RequestMethod.GET})
@PreAuthorize("isAuthenticated()")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
return test(request, response);
}
public ModelAndView test(HttpServletRequest request, HttpServletResponse response) throws Exception {
...
}
在这个例子中它不起作用 - @RequestMapping和@PreAuthorizeannotate不同的方法:
@Controller
public class MyController {
@RequestMapping(value = "/test", method = {RequestMethod.POST, RequestMethod.GET})
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
return test(request, response);
}
@PreAuthorize("isAuthenticated()")
public ModelAndView test(HttpServletRequest request, HttpServletResponse response) throws Exception {
...
}
这种奇怪行为的原因可能是什么?
【问题讨论】:
标签: java spring spring-mvc spring-security spring-annotations