如果需要获取一张图片但服务器没有过滤图片请求地址时,每次请求图片都需要携带token等安全验证密钥,可到nacos配置网关(gateway)的security配置,可过滤掉你配置的url(可理解为白名单)。找到:
security:
oauth2:
...
ignore:
urls:
在urls中添加你需要过滤的地址,注意,这里不需要写在网关中配置的前缀,例如:/blog/xxx/xxx,blog不需要写,例如需要配置如下路径:
@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
原文:https://www.cnblogs.com/upyou/p/13796025.html