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,6 +20,16 @@ public class Constants | ||
| 20 | public static final String GBK = "GBK"; | 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 | public static final String SUCCESS = "0"; | 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,7 +26,7 @@ public class UserConstants | ||
| 26 | 26 | ||
| 27 | /** 部门正常状态 */ | 27 | /** 部门正常状态 */ |
| 28 | public static final String DEPT_NORMAL = "0"; | 28 | public static final String DEPT_NORMAL = "0"; |
| 29 | - | 29 | + |
| 30 | /** 部门停用状态 */ | 30 | /** 部门停用状态 */ |
| 31 | public static final String DEPT_DISABLE = "1"; | 31 | public static final String DEPT_DISABLE = "1"; |
| 32 | 32 | ||
| @@ -36,6 +36,12 @@ public class UserConstants | @@ -36,6 +36,12 @@ public class UserConstants | ||
| 36 | /** 是否为系统默认(是) */ | 36 | /** 是否为系统默认(是) */ |
| 37 | public static final String YES = "Y"; | 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 | public final static String UNIQUE = "0"; | 46 | public final static String UNIQUE = "0"; |
| 41 | public final static String NOT_UNIQUE = "1"; | 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,9 +12,11 @@ import org.springframework.web.bind.annotation.PutMapping; | ||
| 12 | import org.springframework.web.bind.annotation.RequestBody; | 12 | import org.springframework.web.bind.annotation.RequestBody; |
| 13 | import org.springframework.web.bind.annotation.RequestMapping; | 13 | import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | import org.springframework.web.bind.annotation.RestController; | 14 | import org.springframework.web.bind.annotation.RestController; |
| 15 | +import com.ruoyi.common.constant.Constants; | ||
| 15 | import com.ruoyi.common.constant.UserConstants; | 16 | import com.ruoyi.common.constant.UserConstants; |
| 16 | import com.ruoyi.common.utils.SecurityUtils; | 17 | import com.ruoyi.common.utils.SecurityUtils; |
| 17 | import com.ruoyi.common.utils.ServletUtils; | 18 | import com.ruoyi.common.utils.ServletUtils; |
| 19 | +import com.ruoyi.common.utils.StringUtils; | ||
| 18 | import com.ruoyi.framework.aspectj.lang.annotation.Log; | 20 | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| 19 | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; | 21 | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| 20 | import com.ruoyi.framework.security.LoginUser; | 22 | import com.ruoyi.framework.security.LoginUser; |
| @@ -100,6 +102,11 @@ public class SysMenuController extends BaseController | @@ -100,6 +102,11 @@ public class SysMenuController extends BaseController | ||
| 100 | { | 102 | { |
| 101 | return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); | 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 | menu.setCreateBy(SecurityUtils.getUsername()); | 110 | menu.setCreateBy(SecurityUtils.getUsername()); |
| 104 | return toAjax(menuService.insertMenu(menu)); | 111 | return toAjax(menuService.insertMenu(menu)); |
| 105 | } | 112 | } |
| @@ -116,6 +123,11 @@ public class SysMenuController extends BaseController | @@ -116,6 +123,11 @@ public class SysMenuController extends BaseController | ||
| 116 | { | 123 | { |
| 117 | return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); | 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 | menu.setUpdateBy(SecurityUtils.getUsername()); | 131 | menu.setUpdateBy(SecurityUtils.getUsername()); |
| 120 | return toAjax(menuService.updateMenu(menu)); | 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,7 +298,7 @@ public class SysMenuServiceImpl implements ISysMenuService | ||
| 298 | { | 298 | { |
| 299 | String routerPath = menu.getPath(); | 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 | routerPath = "/" + menu.getPath(); | 303 | routerPath = "/" + menu.getPath(); |
| 304 | } | 304 | } |