网站开发合同审核要点,以背景做网站视频为,什么网站可以接设计方案,动易门户网站价格文章目录 数据权限接口权限 前言#xff1a;最近博主在按照bladeX官方文档 配置数据权限 结果发现失效了#xff0c;网上搜了一下没找到合适的答案#xff0c;本着求人不如求己的精神#xff0c;自己调试了一下发现了问题所在#xff0c;也大致看了一下bladeX的权限逻辑。… 文章目录 数据权限接口权限 前言最近博主在按照bladeX官方文档 配置数据权限 结果发现失效了网上搜了一下没找到合适的答案本着求人不如求己的精神自己调试了一下发现了问题所在也大致看了一下bladeX的权限逻辑。 数据权限
简述一下数据权限原理 通过一个dataScope拦截器将用户的业务sql进行拦截拼接拼接一个where条件进行数据过滤 where条件就是我们在web配置的sql, 例如我们原始sql是 select id,name from customer , 配置的过滤规则为 where scope.name ‘admin’, 拼接后就是 select * from ( select id,name from customer) scope where scope.name ‘admin’
所以核心在于DataScopeInterceptor是否生效我们可以在DataScopeInterceptor类的intercept方法第一行打上断点去分析问题到底出在哪里。 博主是连这个方法都没有进来一时间有点懵因为短时间不可能去看大量源码找到所有的调用链路。
这里提供一个思路首先还是尽可能在网上找有没有人遇到这个问题 原因可能是什么如果实在找不到把bladeX原始项目跑一遍原始的商业项目肯定是经过了测试的 数据权限应该不会失效找到代码调用链路我们回到自己的项目中 在关键节点打上断点
至于博主是如何找到DataScopeInterceptor的因为bladeX提供的数据权限注解是DataAuth, 注解要生效 那可能就是通过拦截器或者切面去拦截了所以注解所在的地方应该会有相关代码 在经过大量的调试后最终发现了问题所在 DataScopeInterceptor implements QueryInterceptorqueryInterceptor通过paginationInterceptor类设置的 在bladeX中 定义了一个PaginationInterceptor的子类BladePaginationInterceptor定义的QueryInterceptor数组用于接收queryInterceptor, BladePaginationInterceptor的queryInterceptor又是通过MybatisPlusConfiguration配置类中 注册MybatisPlusInterceptor bean时set的, 我们注意到 ConditionalOnMissingBean({MybatisPlusInterceptor.class}) , 而我们项目中通常都会自定义 MybatisPlusInterceptor 这就导致了bladeX的配置未生效。 解决方案修改我们自定义的MybatisPlusInterceptor , 代码示例
Configuration
public class MybatisPlusExternalConfig {Autowiredprivate DataScopeInterceptor dataScopeInterceptor;Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(ObjectProviderListInnerInterceptor innerInterceptors) {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();ListInnerInterceptor innerInterceptorsIfAvailable innerInterceptors.getIfAvailable();if (innerInterceptorsIfAvailable ! null innerInterceptorsIfAvailable.size() 0) {for (InnerInterceptor innerInterceptor : innerInterceptorsIfAvailable) {interceptor.addInnerInterceptor(innerInterceptor);}}/*** {link org.springblade.core.mp.config.MybatisPlusConfiguration#mybatisPlusInterceptor}* {link org.springblade.core.datascope.interceptor.DataScopeInnerInterceptor}*/BladePaginationInterceptor paginationInnerInterceptor new BladePaginationInterceptor();// 核心步骤paginationInnerInterceptor.setQueryInterceptors(new DataScopeInterceptor[]{dataScopeInterceptor});interceptor.addInnerInterceptor(paginationInnerInterceptor);return interceptor;}}接口权限
bladeX的接口权限原理也比较简单
原理是内置查表sql 将权限code存入BladePermissionHandler中当请求接口时 通过切面拦截PreAuth判断code是否匹配 最后欢迎各位同学前往idea插件marketplace免费下载博主的原创插件 Equals Inspection 感谢各位。