2013-07-23 406 views
6

我有一个情况我需要的路径变量传递的参数传递给预授权如何使用路径变量@Preauthorize

@RequestMapping(value="/page/{cmd}", method = RequestMethod.GET) 
    @PreAuthorize("hasRole(#cmd)") 
    public void method(@PathVariable String cmd, HttpServletRequest request, HttpServletResponse response){ 
// my stuff 
} 

它不working.can有人建议我如何使用路径请在预授权变量。

回答

2

Spring Security的@PreAuthorize用于授权访问的方法。它不知道是不是真的很了解Spring MVC的,尤其是关于其@RequestMapping注释。

的名字,像#cmd将把方法的参数,和你的cmd参数为空。它更改为:

@PathVariable("cmd") String cmd 

这样,cmd路径变量将被绑定到cmd方法参数,这将随后通过#cmd@PreAuthorize的约束。