当前位置: 首页 > news >正文

OneCode 3.0 权限引擎实现详解:基于esdright模块的设计与架构

引言

权限管理是企业级应用的核心功能之一,OneCode 3.0通过esdright模块构建了一套灵活可扩展的权限引擎,支持组件、模块、流程等多维度的权限控制。本文将深入剖析其实现架构、核心组件及设计思想。

总体架构设计

OneCode权限引擎采用分层设计,通过类型化定义、树形结构展示和服务化处理构建完整权限体系:

1. 权限类型体系

通过RightType枚举定义三大核心权限类型,采用枚举扩展模式支持未来功能扩展:

public enum RightType implements TreeItem {comright("组件权限", "bpmfont bpmgongzuoliuzhutiguizeweihuguanli", true, false, false, AttributeNavService.class),moduleright("模块权限", "bpmfont bpmgongzuoliuxitongpeizhi", true, false, false, MenuFormulaService.class),bpmright("流程授权", "spafont spa-icon-app", true, false, false, BPMTreeRightIndex.class);// ... 类型定义与绑定类实现
}

每种权限类型绑定对应的处理类,实现职责分离。

2. 权限树结构设计

采用树形结构展示权限层级关系,核心实现包括:

  • BPMRightTree:流程权限树节点,关联流程定义ID和活动定义ID
  • ComRightTree:组件权限树节点,支持属性类型和公式类型双重分类
  • ModuleRightTree:模块权限树节点,关联模块定义信息

树节点通过@ChildTreeAnnotation实现动态加载,如组件权限树绑定AttributeNavService实现子节点加载:

@ChildTreeAnnotation(bindClass = AttributeNavService.class)
public ComRightTree(Attributetype attributetype, String currentClassName) {this.caption = attributetype.getName();this.currentClassName = currentClassName;this.id = attributetype.getType();this.imageClass = attributetype.getImageClass();this.attributetype = attributetype;
}

核心服务实现

权限引擎通过多个服务类实现权限的管理、验证和控制逻辑:

1. 权限入口控制器

RightIndex作为权限管理的入口控制器,提供三大权限类型的访问端点:

@Controller
@RequestMapping("/esd/right/")
@MethodChinaName(cname = "权限管理")
public class RightIndex {@MethodChinaName(cname = "组件授权")@RequestMapping(method = RequestMethod.POST, value = "ComRight")public TreeListResultModel<List<ComRightTree>> getComRight(String id, String projectName, String currentClassName) { ... }@MethodChinaName(cname = "模块授权")@RequestMapping(method = RequestMethod.POST, value = "ModuleRight")public TreeListResultModel<List<ModuleRightTree>> getModuleRight(String id, String projectName, String className) { ... }@MethodChinaName(cname = "流程授权")@RequestMapping(method = RequestMethod.POST, value = "BpmRight")public TreeListResultModel<List<BPMRightTree>> getBpmRight(String id, String projectName, String className) { ... }
}

通过@RequestMapping定义REST接口,使用TreePageUtil构建树形返回结果。

2. 模块权限服务

ModuleFormulaService实现模块权限的核心逻辑,包括表达式CRUD和权限验证:

  • 表达式管理:支持权限表达式的添加、编辑、删除和查询
  • 树形展示:通过getFormulaTree方法提供权限选择树
  • 权限验证:通过ESDClient与后端交互验证权限

关键实现代码:

@RequestMapping(method = RequestMethod.POST, value = "Index")
public ListResultModel<List<ModuleInstGridView>> getFormulaInstList(String projectName) {ListResultModel<List<ModuleInstGridView>> resultModel = new ListResultModel<>();try {Project config = ESDFacrory.getAdminESDClient().getProjectByName(projectName);List<FormulaInst> list = config.getFormulas();List<FormulaInst> instList = new ArrayList<>();for (FormulaInst inst : list) {if (inst.getFormulaType() != null && inst.getFormulaType().equals(FormulaType.ModuleRight)) {instList.add(inst);}}resultModel = PageUtil.getDefaultPageList(instList, ModuleInstGridView.class);} catch (JDSException e) {e.printStackTrace();}return resultModel;
}

3. 动作权限服务

ActionFormulaService专注于组件动作级别的权限控制,实现细粒度的操作权限管理:

@RequestMapping(method = RequestMethod.POST, value = "Index")
public ListResultModel<List<ModuleActionGridView>> getFormulaInstList(String projectName, String currentClassName) {// 从模块配置中筛选动作权限表达式ProjectVersion version = ESDFacrory.getAdminESDClient().getProjectVersionByName(projectName);EUModule euModule = ESDFacrory.getAdminESDClient().getModule(currentClassName, version.getVersionName());List<ModuleFormulaInst> list = euModule.getComponent().getFormulas();// ... 筛选与转换逻辑
}

组织权限集成

权限引擎与组织架构深度集成,通过org包下的服务类实现基于组织的权限控制:

1. 流程权限集成

BPMTreeRightIndex实现流程节点级别的权限控制,关联流程定义和活动定义:

@RequestMapping(method = RequestMethod.POST, value = "BPMRightNav")
public TreeListResultModel<List<BPMRightTree>> getOrgRightNav(String activityDefId, String processDefId, String projectName) {return TreePageUtil.getTreeList(Arrays.asList(BPMRightFormulaType.values()), BPMRightTree.class);
}

2. 阅办人授权

ReadFormulaService实现文档阅办权限的精细化控制,支持阅办人表达式的管理:

@RequestMapping(method = RequestMethod.POST, value = "Index")
public ListResultModel<List<ReadGridView>> getFormulaInstList(String projectId) {// 筛选阅办人权限表达式List<FormulaInst> instList = new ArrayList<>();for (FormulaInst inst : list) {if (inst != null && inst.getFormulaType() != null && inst.getFormulaType().equals(FormulaType.ReaderSelectedID)) {instList.add(inst);}}// ...
}

属性权限控制

AttributeNavService实现基于属性的权限控制,支持不同属性类型的权限差异化管理:

@RequestMapping(method = RequestMethod.POST, value = "FormulaList")
public ListResultModel<List<PageRightGridView>> getFormulaList(FormulaType formulaType, String projectName, String currentClassName) {// 根据公式类型筛选权限表达式List<FormulaInst> instList = new ArrayList<>();for (FormulaInst inst : list) {if (inst != null && inst.getFormulaType() != null && inst.getFormulaType().equals(formulaType)) {instList.add(inst);}}// ...
}

权限表达式引擎

权限引擎的核心在于表达式处理,通过公式定义实现灵活的权限规则:

  1. 表达式类型:通过FormulaType枚举定义多种权限表达式类型
  2. 表达式管理:支持表达式的添加、编辑、删除和查询
  3. 表达式执行:通过ESDFacrory.getAdminESDClient()与后端交互执行权限验证

关键代码示例(添加表达式):

@RequestMapping(value = {"addFormula"}, method = {RequestMethod.GET, RequestMethod.POST})
public @ResponseBody ResultModel<Boolean> addFormulaInst(String SelectFormulaTree, String projectName) {try {Project config = ESDFacrory.getAdminESDClient().getProjectByName(projectName);String[] formulaIdArr = StringUtility.split(SelectFormulaTree, ";");for (String id : formulaIdArr) {ParticipantSelect select = FormulaFactory.getInstance(ESDFacrory.getAdminESDClient().getSpace()).getFormulaById(id);FormulaInst inst = new FormulaInst();inst.setExpression(select.getFormula());inst.setFormulaType(select.getFormulaType());inst.setParticipantSelectId(select.getParticipantSelectId());inst.setName(select.getSelectName());inst.setFormulaInstId(UUID.randomUUID().toString());ESDFacrory.getAdminESDClient().updateFormulaConfig(config.getId(),inst);}} catch (JDSException e) {e.printStackTrace();}return resultModel;
}

与OneCode核心设计的契合

权限引擎深度融合OneCode的两大核心设计理念:

  1. 注解驱动开发:大量使用自定义注解实现权限元数据定义

    • @MethodChinaName:定义权限中文名称
    • @NavTreeViewAnnotation:声明树形导航视图
    • @APIEventAnnotation:绑定API事件处理
  2. 元数据驱动开发:通过FormulaInst等元数据对象描述权限规则,实现配置化权限管理

总结与展望

OneCode 3.0权限引擎通过类型化、层次化、服务化的设计,构建了灵活强大的权限管理体系。核心优势包括:

  • 多维度权限控制:支持组件、模块、流程等多层面权限管理
  • 细粒度权限定义:从功能到数据的精细化权限控制
  • 灵活的表达式引擎:通过公式定义实现复杂权限规则
  • 与组织架构深度集成:基于组织的权限分配与控制

未来可进一步增强AI能力,如基于用户行为推荐权限配置、智能检测权限冲突等,提升权限管理的智能化水平。


文章转载自:
http://abjure.sxnf.com.cn
http://catgut.sxnf.com.cn
http://canting.sxnf.com.cn
http://bridget.sxnf.com.cn
http://betwixt.sxnf.com.cn
http://aeronautic.sxnf.com.cn
http://antrustion.sxnf.com.cn
http://avestan.sxnf.com.cn
http://according.sxnf.com.cn
http://afterbrain.sxnf.com.cn
http://antihydrogen.sxnf.com.cn
http://bemusement.sxnf.com.cn
http://cafe.sxnf.com.cn
http://battu.sxnf.com.cn
http://chromatopsia.sxnf.com.cn
http://chiliasm.sxnf.com.cn
http://choreoid.sxnf.com.cn
http://bly.sxnf.com.cn
http://cardcase.sxnf.com.cn
http://chemosmotic.sxnf.com.cn
http://acuminous.sxnf.com.cn
http://atmometer.sxnf.com.cn
http://anisocytosis.sxnf.com.cn
http://burdensome.sxnf.com.cn
http://adverbially.sxnf.com.cn
http://acardia.sxnf.com.cn
http://caries.sxnf.com.cn
http://abscission.sxnf.com.cn
http://bide.sxnf.com.cn
http://aviatic.sxnf.com.cn
http://www.dtcms.com/a/277788.html

相关文章:

  • 【micro:bit】从入门到放弃(一):在线、离线版本的使用
  • 代码部落 20250713 CSP-J复赛 模拟赛
  • 适配器模式:兼容不兼容接口
  • C++--unordered_set和unordered_map的使用
  • C#接口进阶:继承与多态实战解析
  • DVWA靶场通关笔记-XSS DOM(Medium级别)
  • 在人工智能自动化编程时代:AI驱动开发和传统软件开发的分析对比
  • 如何自动化处理TXT日志,提升工作效率新方式
  • Autotab:用“屏幕录制”训练AI助手,解锁企业级自动化新范式
  • Springboot实现一个接口加密
  • 免费证件照工具,一键制作超方便
  • Linux驱动开发2:字符设备驱动
  • NumPy实战指南:解锁科学计算的超能力
  • 5.适配器模式
  • Chrome浏览器此扩展程序已停用,因为它已不再受支持,插件被停用解决方案
  • 解决 Python 跨目录导入模块问题
  • Ubuntu 设置自动挂载 SD 卡,扩容根目录
  • 进程互斥的硬件实现方法
  • Python----大模型(Langchain-Prompt提示词)
  • 快速搭建Maven仓库服务
  • 大话数据结构之 <顺序表> (C语言)
  • 学习:JS基础[5]对象
  • 【SpringAI Alibaba】基于 Redis 实现连续对话与向量存储
  • VsCode的LivePreview插件应用
  • [Java恶补day41] 226. 翻转二叉树
  • 基于springboot的大学公文收发管理系统
  • AB实验评估指标体系之【实验评估指标体系】
  • 015_引用功能与信息溯源
  • python 字典(Dictionary) vs. 集合(Set):它们是如何做到快速查找的?为什么字典的键(key)必须是不可变的?
  • S7-1200 与 ET200SP:PROFINET 设备关键数据 IP 地址、MAC 地址及 MRP 环状态获取