From 9c64365c3fded7be4c66248e0c90c456a4915529 Mon Sep 17 00:00:00 2001 From: scott Date: Sat, 24 Oct 2026 05:34:35 -0400 Subject: [PATCH] =?UTF-8?q?fix(system):=20=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E9=9B=86=E6=88=90=E9=85=8D=E7=BD=AE=E6=96=B0=E5=A2=9E/?= =?UTF-8?q?=E7=BC=96=E8=BE=91/=E6=9F=A5=E8=AF=A2=E8=A1=A5=E6=9D=83?= =?UTF-8?q?=E9=99=90=E4=B8=8E=E7=A7=9F=E6=88=B7=E5=BD=92=E5=B1=9E=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=EF=BC=8C=E9=99=84=E6=8C=89=E9=92=AE=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../system/controller/ThirdAppController.java | 54 ++++++++++++++++++- ...add_thirdapp_config_button_permissions.sql | 13 +++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.5_4__add_thirdapp_config_button_permissions.sql diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/ThirdAppController.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/ThirdAppController.java index 90c84b246..8c7f92fee 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/ThirdAppController.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/ThirdAppController.java @@ -11,8 +11,10 @@ import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.api.vo.Result; import org.jeecg.common.config.TenantContext; import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.exception.JeecgBootBizTipException; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.enums.MessageTypeEnum; +import org.jeecg.common.constant.enums.SysRoleEnum; import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.TokenUtils; @@ -20,6 +22,7 @@ import org.jeecg.common.util.oConvertUtils; import org.jeecg.config.mybatis.MybatisPlusSaasConfig; import org.jeecg.modules.system.entity.SysThirdAccount; import org.jeecg.modules.system.entity.SysThirdAppConfig; +import org.jeecg.modules.system.service.ISysTenantPackService; import org.jeecg.modules.system.service.ISysThirdAccountService; import org.jeecg.modules.system.service.ISysThirdAppConfigService; import org.jeecg.modules.system.service.impl.ThirdAppDingtalkServiceImpl; @@ -59,6 +62,11 @@ public class ThirdAppController { @Autowired private ISysThirdAccountService sysThirdAccountService; + //update-begin---author:scott ---date:20261020 for:新增第三方集成配置管理权限校验(本租户组织账户管理员分支用)----------- + @Autowired + private ISysTenantPackService sysTenantPackService; + //update-end---author:scott ---date:20261020 for:----------- + /** * 获取启用的系统 */ @@ -380,6 +388,9 @@ public class ThirdAppController { Result result = new Result<>(); //根据当前登录租户id和第三方类别判断是否已经创建 Integer tenantId = oConvertUtils.isNotEmpty(appConfig.getTenantId()) ? appConfig.getTenantId() : oConvertUtils.getInt(TenantContext.getTenant(), 0); + //update-begin---author:scott ---date:20261020 for:权限+对象级双重校验:admin/system:third:config:add权限码/本租户组织账户管理员三选一放行,防止任意登录用户新建其他租户的第三方配置----------- + assertThirdConfigManager(tenantId, "system:third:config:add"); + //update-end---author:scott ---date:20261020 for:----------- SysThirdAppConfig config = appConfigService.getThirdConfigByThirdType(tenantId, appConfig.getThirdType()); if (null != config) { result.error500("操作失败,同一个租户下只允许绑定一个钉钉或者企业微信"); @@ -417,6 +428,9 @@ public class ThirdAppController { result.error500("数据不存在"); return result; } + //update-begin---author:wangshuai ---date:20261021 for:校验当前用户能否管理指定租户的第三方集成配置----------- + assertThirdConfigManager(config.getTenantId(), "system:third:config:edit"); + //update-end---author:wangshuai ---date:20261021 for:校验当前用户能否管理指定租户的第三方集成配置----------- String clientId = appConfig.getClientId(); //如果编辑的应用key,和数据库中的不一致,需要判断应用key是否已存在 if(!clientId.equals(config.getClientId())){ @@ -427,8 +441,17 @@ public class ThirdAppController { return result; } } + //update-begin---author:wangshuai ---date:20261021 for:校验当前用户能否管理指定租户的第三方集成配置----------- + config.setAgentId(appConfig.getAgentId()); + config.setClientId(clientId); + if (oConvertUtils.isNotEmpty(appConfig.getClientSecret())) { + config.setClientSecret(appConfig.getClientSecret()); + } + config.setCorpId(appConfig.getCorpId()); + config.setStatus(appConfig.getStatus()); + //update-end---author:wangshuai ---date:20261021 for:校验当前用户能否管理指定租户的第三方集成配置----------- try { - appConfigService.updateById(appConfig); + appConfigService.updateById(config); result.success("修改成功!"); } catch (Exception e) { log.error(e.getMessage(), e); @@ -482,6 +505,9 @@ public class ThirdAppController { tenantId = oConvertUtils.getInt(TenantContext.getTenant(), 0); } } + //update-begin---author:wangshuai ---date:20261021 for:校验当前用户能否管理指定租户的第三方集成配置----------- + assertThirdConfigManager(tenantId, "system:third:config:query"); + //update-end---author:wangshuai ---date:20261021 for:校验当前用户能否管理指定租户的第三方集成配置----------- Result result = new Result<>(); LambdaQueryWrapper query = new LambdaQueryWrapper<>(); query.eq(SysThirdAppConfig::getThirdType,thirdType); @@ -629,4 +655,30 @@ public class ThirdAppController { List jwSysUserDepartVos = wechatEnterpriseService.getThirdUserBindByWechat(tenantId); return Result.ok(jwSysUserDepartVos); } + + //update-begin---author:wangshuai ---date:2026101 for:校验当前用户能否管理指定租户的第三方集成配置 --- + /* + * 校验当前用户能否管理指定租户的第三方集成配置:admin/系统租户管理员放行,持有 permCodes 中任一权限码放行, + * 否则须为该租户的组织账户管理员或超级管理员(敲敲云组织页自助配置用,对应 sys_tenant_pack_user)。 + * + * @param tenantId 租户ID + * @param permCodes 允许放行的按钮权限码(新增/编辑/查询各自独立的权限码,调用方按自己的动作传对应的码) + * @author wangshuai + */ + private void assertThirdConfigManager(Integer tenantId, String... permCodes) { + if (SysRoleEnum.hasAnyRole(SysRoleEnum.ADMIN, SysRoleEnum.TENANT_ADMIN)) { + return; + } + for (String permCode : permCodes) { + if (SecurityUtils.getSubject().isPermitted(permCode)) { + return; + } + } + try { + sysTenantPackService.izHaveManageUserAuth(String.valueOf(tenantId)); + } catch (Exception e) { + throw new JeecgBootBizTipException("无权限,请联系管理员"); + } + } + //update-end---author:wangshuai ---date:20261021 for:校验当前用户能否管理指定租户的第三方集成配置----------- } diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.5_4__add_thirdapp_config_button_permissions.sql b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.5_4__add_thirdapp_config_button_permissions.sql new file mode 100644 index 000000000..255132796 --- /dev/null +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.5_4__add_thirdapp_config_button_permissions.sql @@ -0,0 +1,13 @@ +-- ---author:wangshuai---date:20261021-----for:第三方集成配置(钉钉/企微/飞书)可被任意登录用户越权覆写、clientSecret明文回显;addThirdAppConfig/editThirdAppConfig/getThirdConfigByTenantId 分别补充 system:third:config:add/edit/query 按钮权限并授权给系统管理员角色(parent_id=1629109281748291586 为"第三方配置"菜单,同级已有 system:third:config:delete);该菜单此前 is_leaf=1,但早已有 delete 这个子项、一直没同步改过,顺带一并修正 +-- 1. 新增按钮权限 +INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`) VALUES ('2026102000000000001', '1629109281748291586', '第三方配置编辑', NULL, NULL, 0, NULL, NULL, 2, 'system:third:config:edit', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2026-10-20 10:00:00', NULL, NULL, 0, 0, '1', 0); +INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`) VALUES ('2026102000000000002', '1629109281748291586', '第三方配置新增', NULL, NULL, 0, NULL, NULL, 2, 'system:third:config:add', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2026-10-20 10:00:00', NULL, NULL, 0, 0, '1', 0); +INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`) VALUES ('2026102000000000003', '1629109281748291586', '第三方配置查询', NULL, NULL, 0, NULL, NULL, 2, 'system:third:config:query', '1', NULL, 0, NULL, 1, 0, 0, 0, NULL, 'admin', '2026-10-20 10:00:00', NULL, NULL, 0, 0, '1', 0); + +-- 2. 授权给系统管理员角色(f6817f48af4fb3af11b9e8bf182f618b) +INSERT INTO `sys_role_permission` (`id`, `role_id`, `permission_id`, `data_rule_ids`, `operate_date`, `operate_ip`) VALUES ('2026102000000000021', 'f6817f48af4fb3af11b9e8bf182f618b', '2026102000000000001', NULL, '2026-10-20 10:00:00', '127.0.0.1'); +INSERT INTO `sys_role_permission` (`id`, `role_id`, `permission_id`, `data_rule_ids`, `operate_date`, `operate_ip`) VALUES ('2026102000000000022', 'f6817f48af4fb3af11b9e8bf182f618b', '2026102000000000002', NULL, '2026-10-20 10:00:00', '127.0.0.1'); +INSERT INTO `sys_role_permission` (`id`, `role_id`, `permission_id`, `data_rule_ids`, `operate_date`, `operate_ip`) VALUES ('2026102000000000023', 'f6817f48af4fb3af11b9e8bf182f618b', '2026102000000000003', NULL, '2026-10-20 10:00:00', '127.0.0.1'); + +-- 3. "第三方配置"菜单改为非叶子节点(is_leaf: 1→0),否则角色权限树里不会把上面新增的按钮权限正确展示为其子项 +UPDATE `sys_permission` SET `is_leaf` = 0 WHERE `id` = '1629109281748291586';