Ruoyi-App前台路由白名单配置
时间: 2023-07-26 19:43:40 浏览: 92
Ruoyi-App 前台路由的白名单配置可以在项目的 application.properties 文件中进行配置,具体如下:
1. 在 application.properties 文件中添加以下配置:
```
# 配置前台路由白名单,多个路由使用逗号分隔
ruoyi.app.front-router.white-list=/dashboard,/profile
```
2. 在代码中获取白名单路由并进行验证:
```
// 获取前台路由白名单
String frontRouterWhiteList = Global.getProperty("ruoyi.app.front-router.white-list");
// 判断是否在白名单中
if (StringUtils.isNotEmpty(frontRouterWhiteList))
{
String[] routers = frontRouterWhiteList.split(",");
if (!Arrays.asList(routers).contains(router))
{
throw new BusinessException("非法路由:" + router);
}
}
```
其中,router 为客户端请求的路由地址,可以通过 HttpServletRequest 获取。上述代码中,通过 Global.getProperty("ruoyi.app.front-router.white-list") 获取配置文件中的前台路由白名单,然后判断客户端请求的路由地址是否在白名单中,如果不在则抛出异常。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)