Commit c1db17dd771f202647ec56898f6b09cf00947a26
1 parent
30be2a08
限制外链地址必须以http(s)://开头
Showing
4 changed files
with
30 additions
and
2 deletions
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
| ... | ... | @@ -20,6 +20,16 @@ public class Constants |
| 20 | 20 | public static final String GBK = "GBK"; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | + * http请求 | |
| 24 | + */ | |
| 25 | + public static final String HTTP = "http://"; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * https请求 | |
| 29 | + */ | |
| 30 | + public static final String HTTPS = "https://"; | |
| 31 | + | |
| 32 | + /** | |
| 23 | 33 | * 通用成功标识 |
| 24 | 34 | */ |
| 25 | 35 | public static final String SUCCESS = "0"; | ... | ... |
ruoyi/src/main/java/com/ruoyi/common/constant/UserConstants.java
| ... | ... | @@ -26,7 +26,7 @@ public class UserConstants |
| 26 | 26 | |
| 27 | 27 | /** 部门正常状态 */ |
| 28 | 28 | public static final String DEPT_NORMAL = "0"; |
| 29 | - | |
| 29 | + | |
| 30 | 30 | /** 部门停用状态 */ |
| 31 | 31 | public static final String DEPT_DISABLE = "1"; |
| 32 | 32 | |
| ... | ... | @@ -36,6 +36,12 @@ public class UserConstants |
| 36 | 36 | /** 是否为系统默认(是) */ |
| 37 | 37 | public static final String YES = "Y"; |
| 38 | 38 | |
| 39 | + /** 是否菜单外链(是) */ | |
| 40 | + public static final String YES_FRAME = "0"; | |
| 41 | + | |
| 42 | + /** 是否菜单外链(否) */ | |
| 43 | + public static final String NO_FRAME = "1"; | |
| 44 | + | |
| 39 | 45 | /** 校验返回结果码 */ |
| 40 | 46 | public final static String UNIQUE = "0"; |
| 41 | 47 | public final static String NOT_UNIQUE = "1"; | ... | ... |
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java
| ... | ... | @@ -12,9 +12,11 @@ import org.springframework.web.bind.annotation.PutMapping; |
| 12 | 12 | import org.springframework.web.bind.annotation.RequestBody; |
| 13 | 13 | import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | 14 | import org.springframework.web.bind.annotation.RestController; |
| 15 | +import com.ruoyi.common.constant.Constants; | |
| 15 | 16 | import com.ruoyi.common.constant.UserConstants; |
| 16 | 17 | import com.ruoyi.common.utils.SecurityUtils; |
| 17 | 18 | import com.ruoyi.common.utils.ServletUtils; |
| 19 | +import com.ruoyi.common.utils.StringUtils; | |
| 18 | 20 | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| 19 | 21 | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| 20 | 22 | import com.ruoyi.framework.security.LoginUser; |
| ... | ... | @@ -100,6 +102,11 @@ public class SysMenuController extends BaseController |
| 100 | 102 | { |
| 101 | 103 | return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); |
| 102 | 104 | } |
| 105 | + else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) | |
| 106 | + && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) | |
| 107 | + { | |
| 108 | + return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); | |
| 109 | + } | |
| 103 | 110 | menu.setCreateBy(SecurityUtils.getUsername()); |
| 104 | 111 | return toAjax(menuService.insertMenu(menu)); |
| 105 | 112 | } |
| ... | ... | @@ -116,6 +123,11 @@ public class SysMenuController extends BaseController |
| 116 | 123 | { |
| 117 | 124 | return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); |
| 118 | 125 | } |
| 126 | + else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) | |
| 127 | + && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) | |
| 128 | + { | |
| 129 | + return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); | |
| 130 | + } | |
| 119 | 131 | menu.setUpdateBy(SecurityUtils.getUsername()); |
| 120 | 132 | return toAjax(menuService.updateMenu(menu)); |
| 121 | 133 | } | ... | ... |
ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java
| ... | ... | @@ -298,7 +298,7 @@ public class SysMenuServiceImpl implements ISysMenuService |
| 298 | 298 | { |
| 299 | 299 | String routerPath = menu.getPath(); |
| 300 | 300 | // 非外链并且是一级目录 |
| 301 | - if (0 == menu.getParentId() && "1".equals(menu.getIsFrame())) | |
| 301 | + if (0 == menu.getParentId() && UserConstants.NO_FRAME.equals(menu.getIsFrame())) | |
| 302 | 302 | { |
| 303 | 303 | routerPath = "/" + menu.getPath(); |
| 304 | 304 | } | ... | ... |