fix(system): 第三方集成配置新增/编辑/查询补权限与租户归属校验,附按钮权限升级 SQL

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
scott 2026-10-24 05:34:35 -04:00
parent 0582032e91
commit 9c64365c3f
2 changed files with 66 additions and 1 deletions

View File

@ -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<String> 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<SysThirdAppConfig> result = new Result<>();
LambdaQueryWrapper<SysThirdAppConfig> query = new LambdaQueryWrapper<>();
query.eq(SysThirdAppConfig::getThirdType,thirdType);
@ -629,4 +655,30 @@ public class ThirdAppController {
List<JwUserDepartVo> 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:校验当前用户能否管理指定租户的第三方集成配置-----------
}

View File

@ -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';