SpringCloud gateway 过滤

如果需要获取一张图片但服务器没有过滤图片请求地址时,每次请求图片都需要携带token等安全验证密钥,可到nacos配置网关(gateway)的security配置,可过滤掉你配置的url(可理解为白名单)。找到:

security:
  oauth2:
       ...
    ignore:
      urls: 

urls中添加你需要过滤的地址,注意,这里不需要写在网关中配置的前缀,例如:/blog/xxx/xxxblog不需要写,例如需要配置如下路径:

@RestController
@RequestMapping("/articles/")
public class ArticlesController {
    /**
     * 获取博文图片
     *
     * @param memberId 用户id
     * @param filePath 文件名
     */
    @GetMapping("image/{memberId}/{filePath}")
    public void reviewImage(@PathVariable(name = "memberId") String memberId,
                            @PathVariable(name = "filePath") String filePath) {...}
}

需要这么配置:

security:
  oauth2:
    ......
    ignore:
      urls:
        - /articles/image/**/**

如果需要配置多个也和上面配置雷同

security:
  oauth2:
    ......
    ignore:
      urls:
        - /articles/image/**/**
        - xxx/xxx/xxx
        - /xxx/xx
posted @ 2020-10-11 00:52  CloverYou  阅读(951)  评论(0)    收藏  举报