我有一個Spring MVC控制器,並希望通過Spring Method Security來保護它。
在下面的例子它的工作原理 - @RequestMapping
和@PreAuthorize
註釋相同的方法:Spring Security:@PreAuthorize僅與@RequestMapping一起使用
@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
和@PreAuthorize
註釋不同的方法:
@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 {
...
}
什麼可能是這個奇怪的原因b ehaviour?
http://stackoverflow.com/a/19421786/1291150 –
謝謝你 - 這有助於! – olivmir