【问题标题】:How to use path variable in @Preauthorize如何在@Preauthorize 中使用路径变量
【发布时间】:2013-07-22 08:51:36
【问题描述】:

我有一种情况需要将路径变量作为参数传递给预授权

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

它不起作用。请任何人建议我如何在预授权中使用路径变量。

【问题讨论】:

    标签: jakarta-ee spring-security pre-authentication


    【解决方案1】:

    Spring Security 的@PreAuthorize 用于授权对方法的访问。它对 Spring MVC 知之甚少,尤其是它的 @RequestMapping 注释。

    #cmd 之类的名称将引用方法参数,而您的 cmd 参数为空。将其更改为:

    @PathVariable("cmd") String cmd
    

    这样,cmd 路径变量将绑定到 cmd 方法参数,然后将由 #cmd 中的 @PreAuthorize 绑定。

    【讨论】:

      猜你喜欢
      • 2022-01-02
      • 1970-01-01
      • 2017-12-02
      • 2020-05-08
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      • 2020-05-04
      • 1970-01-01
      相关资源
      最近更新 更多