函数如何跳过权限拦截

跳过登录直接调用接口

示例:
  • 跳过queryTea的权限验证
    @Action(displayName = "queryTea", bindingType = ViewTypeEnum.FORM)
    @Action.Advanced(type = FunctionTypeEnum.UPDATE)
    public Teacher queryTea(Teacher data) {
    }
  • 在yaml文件里面配置上该函数的namespace(模型编码)以及函数名字
    pamirs:
      auth:
        fun-filter:
            - namespace: user.PamirsUserTransient
              fun: login #登录
            - namespace: top.Teacher
              fun: queryTea

不跳过登录直接调用接口

示例:
  • 在yaml文件里面配置上该函数的namespace(模型编码)以及函数名字
    pamirs:
      auth:
        fun-filter-only-login: #登录后不再校验该函数的权限
            - namespace: top.Teacher
              fun: queryTea

按包设置权限过滤

  • 如何批量跳过权限验证?以上两种方式提供了在yml文件里面配置权限过滤的方式,但如果需要大量过滤权限,配置就变得很繁琐,所以下面主要介绍通过代码扩展的方式去控制权限。
示例:
  • 以下示例通过控制包路径来跳过权限。

  • 继承pro.shushi.pamirs.auth.api.spi.AuthFilterService接口

    import org.springframework.core.annotation.Order;
    import org.springframework.stereotype.Component;
    @Order(88)
    @Component
    public class CustomAuthFilterService implements AuthFilterService {
    
    public static final String skipClass = "pro.shushi.pamirs.top.core.action";
    
    @Override
    public Boolean isAccessAction(String model, String name) {
        //从缓存中取函数
       Action cacheAction = PamirsSession.getContext().getExtendCache(ActionCacheApi.class).get(model, name);
        if (cacheAction instanceof ServerAction) {
            ServerAction serverAction = (ServerAction) cacheAction;
            Function function = PamirsSession.getContext().getFunction(serverAction.getModel(), serverAction.getFun());
            String clazz = function.getClazz();
            //返回true就代表通过验证
            if (clazz != null && clazz.startsWith(skipClass)) {
                return true;
            }
        }
        return null;
    }
    }

    请求pro.shushi.pamirs.top.core.action路径下的动作可以通过验证。

Oinone社区 作者:yexiu原创文章,如若转载,请注明出处:https://doc.oinone.top/wen-ti-zhen-duan/16299.html

访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验

(0)
yexiu的头像yexiu数式员工
上一篇 2024年8月22日 am12:17
下一篇 2024年8月22日 pm7:51

相关推荐

  • 树表查不到二级目录

    场景:树表结构查不到二级模型内容,联动配置如下 问题:界面只显示部门,不显示岗位。 已知: 自定义部门代理模型继承了PamirsDepartment @Model.model(DepartmentDoc.MODEL_MODEL) @Model.Advanced(type = ModelTypeEnum.PROXY) @Model(displayName = “部门资料代理模型”, summary = “部门资料代理模型”) public class DepartmentDoc extends PamirsDepartment { public static final String MODEL_MODEL = “top.DepartmentDoc”; @Field.many2one @Field(displayName = “上级部门”) private DepartmentDoc parent; @Field.one2many @Field(displayName = “岗位列表”) private List positionLists; } 自定义岗位代理模型继承了PamirsPosition @Model.model(PositionDoc.MODEL_MODEL) @Model(displayName = “岗位代理模型”, summary = “岗位代理模型”) @Model.Advanced(type = ModelTypeEnum.PROXY) public class PositionDoc extends PamirsPosition { public static final String MODEL_MODEL = “top.PositionDoc”; @Field.many2one @Field(displayName = “上级岗位”) private PositionDoc parent; } 首先查看控制台相应请求 找到请求接口进后端debug,pro.shushi.pamirs.boot.web.action.UiTreeAction#fetchChildren 检查这两个数据是否正常 继续debug可知,在queryWrapper中使用departmentCode没有查询出数据,这时候回看模型定义,发现岗位列表中没有定义关联字段,导致没有查出数据。pro.shushi.pamirs.boot.web.manager.tree.UiTreeRelationQueryManager#_fetchIsLeaf 解决:在模型配置中添加关系字段@Field.Relation(relationFields = {"code"}, referenceFields = {"departmentCode"}),并和父类中的关系字段保持一致 部门代理模型: @Model.model(DepartmentDoc.MODEL_MODEL) @Model.Advanced(type = ModelTypeEnum.PROXY) @Model(displayName = "部门资料代理模型", summary = "部门资料代理模型") public class DepartmentDoc extends PamirsDepartment { public static final String MODEL_MODEL = "top.DepartmentDoc"; @Field.many2one @Field.Relation(relationFields = {"parentCode"}, referenceFields = {"code"}) @Field(displayName = "上级部门") private DepartmentDoc parent; @Field.one2many @Field.Relation(relationFields = {"code"}, referenceFields = {"departmentCode"}) @Field(displayName = "岗位列表") private List<PositionDoc> positionLists; } 岗位代理模型 @Model.model(PositionDoc.MODEL_MODEL) @Model(displayName = "岗位代理模型", summary = "岗位代理模型") @Model.Advanced(type = ModelTypeEnum.PROXY) public class PositionDoc extends PamirsPosition { public static final String MODEL_MODEL = "top.PositionDoc"; @Field.many2one @Field.Relation(relationFields = {"departmentCode"}, referenceFields = {"code"}) @Field(displayName = "上级岗位") private PositionDoc parent; }

    2024年7月23日
    54900
  • 序列化工具使用问题

    后端使用的JSON序列化JsonUtils.toJSONString(nodes);前端使用的JSON序列化PamirsJsonUtils.toJSONString(nodes, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat, SerializerFeature.BrowserCompatible);注意:用什么工具序列化,就用什么工具反序列化、parse 的时候,要保持一致, 使用PamirsJsonUtils序列化工具主要是为了解决枚举取值错误的问题以及id精度丢失问题。当出现这两个问题的时候,需要使用PamirsJsonUtils 进行序列化。

    2024年9月5日
    89600
  • 工作流工作台无权限排查路径

    现象:用户前端自定义跳转工作流审批页面,提示无权限 排查路径: 5.0版本权限是根据路径进行鉴权的,请求载荷中variables需要携带path路径。 示例:path=/management_center/AuthMenus_RoleAndPermission_SystemPermission如果是用户自定义跳转页面,需要配置sessionPath:,值为url中的path路径 查看debug信息中权限上下文中角色携带的权限是否正确 复制debug信息中的path路径,去权限上下文中搜索查看该路径下所有的权限 ~~~ “getRoleActionPermissionsByViewAction:workbench.WorkBenchWorkflowUserTaskActive:WorkflowMenus_WorkBenchMenu_ActiveUserTaskMenu”: { “630732547466232342”: { “/workflow/WorkflowMenus_WorkBenchMenu_ActiveUserTaskMenu/ACTION#workbench.WorkBenchWorkflowUserTaskActive#workflow_write/ACTION#workflow.WorkflowUserTask#workflow_writeturnon”: 1, “/workflow/WorkflowMenus_WorkBenchMenu_ActiveUserTaskMenu/ACTION#workbench.WorkBenchWorkflowUserTaskActive#workflow_wait/ACTION#workflow.WorkflowUserTask#workflow_agree”: 1, } }, ~~~ 参数介绍: 630732547466232342:角色630732547466232342拥有的所有权限信息 /workflow/WorkflowMenus_WorkBenchMenu_ActiveUserTaskMenu:path路径 /ACTION#workbench.WorkBenchWorkflowUserTaskActive#workflow_write:此path路径下面的ACTION,模型为workbench.WorkBenchWorkflowUserTaskActive的workflow_write动作。 对比无权限页面和以上参数是否对应。可在页面url上查看模型,动作。常见问题有模型不匹配(更换为正常有权限的模型)、角色下无动作权限。

    2024年8月6日
    56700
  • 前端打包后运行报错: locale is undefined

    前端 monorepo 工程打包的时候可能会遇到如下报错: 解决方案分为四步: 下载这个build脚本,并放到 scripts 目录下,需要解压下载地址 修改 boot 工程的 package.json, 为 scripts 属性添加这两行命令 "prebuild": "node ../../scripts/build/prebuild-only.js", "postbuild": "node ../../scripts/build/postbuild.js", 在根目录执行 pnpm run clean,删除依赖,如果是windows电脑,执行 pnpm run clean:win 重新安装依赖pnpm install,再回到 boot 工程,执行 pnpm run build

    2025年7月18日
    6100
  • 保存多值字段SQL执行报错

    定义多值类型时,字段类型应该设置为List类型。 @Field.String @Field(displayName ="经费证明", multi = true, serialize = Field.serialize.JSON) private List<String> matchFund; 场景复现

    2024年8月30日
    60600

Leave a Reply

登录后才能评论