一、该问题的重现步骤是什么?
按照文档上面的 5.4.2.1 纯注解配置数据权限,但是配置后无效
1)按文档要求在NoticeMapper中进行配置,如下图
我用create_dept作为权限字段,按照文档上面create_dept是默认字段,所以没有配置column
2)为了方便演示,我又根据文档调整了数据库中的数据
3)用postman访问,结果如下
显示的是5条数据,而不是3条
4)后台打印语句如下
2021-03-03 16:39:47.452 DEBUG 16444 --- [ XNIO-1 task-4] o.s.core.tenant.BladeTenantInterceptor : Original SQL: SELECT
n.*,
d.dict_value AS categoryName
FROM
blade_notice n
LEFT JOIN ( SELECT * FROM blade_dict WHERE CODE = 'notice' ) d ON n.category = d.dict_key
WHERE
n.is_deleted = 0 and n.tenant_id = ?
2021-03-03 16:39:47.455 DEBUG 16444 --- [ XNIO-1 task-4] o.s.core.tenant.BladeTenantInterceptor : parser sql: SELECT n.*, d.dict_value AS categoryName FROM blade_notice n LEFT JOIN (SELECT * FROM blade_dict WHERE CODE = 'notice') d ON n.category = d.dict_key WHERE n.is_deleted = 0 AND n.tenant_id = ?
2021-03-03 16:39:47.481 WARN 16444 --- [ XNIO-1 task-4] o.s.c.m.p.BladePaginationInterceptor : optimize this sql to a count sql has exception, sql:"SELECT n.*, d.dict_value AS categoryName FROM blade_notice n LEFT JOIN (SELECT * FROM blade_dict WHERE CODE = 'notice') d ON n.category = d.dict_key WHERE n.is_deleted = 0 AND n.tenant_id = ?", exception:
null
2021-03-03 16:39:47.483 DEBUG 16444 --- [ XNIO-1 task-4] o.s.d.m.N.selectNoticePage_mpCount : ==> Preparing: SELECT COUNT(1) FROM (SELECT n.*, d.dict_value AS categoryName FROM blade_notice n LEFT JOIN (SELECT * FROM blade_dict WHERE CODE = 'notice') d ON n.category = d.dict_key WHERE n.is_deleted = 0 AND n.tenant_id = ?) TOTAL
2021-03-03 16:39:47.486 DEBUG 16444 --- [ XNIO-1 task-4] o.s.d.m.N.selectNoticePage_mpCount : ==> Parameters: 000000(String)
2021-03-03 16:39:47.488 DEBUG 16444 --- [ XNIO-1 task-4] o.s.d.m.N.selectNoticePage_mpCount : <== Total: 1
2021-03-03 16:39:47.491 DEBUG 16444 --- [ XNIO-1 task-4] o.s.d.m.NoticeMapper.selectNoticePage : ==> Preparing: SELECT n.*, d.dict_value AS categoryName FROM blade_notice n LEFT JOIN (SELECT * FROM blade_dict WHERE CODE = 'notice') d ON n.category = d.dict_key WHERE n.is_deleted = 0 AND n.tenant_id = ? LIMIT ?
============== Sql Start ==============
Execute ID :org.springblade.desk.mapper.NoticeMapper.selectNoticePage_mpCount
Execute SQL :SELECT COUNT(1) FROM (SELECT n.*, d.dict_value AS categoryName FROM blade_notice n LEFT JOIN (SELECT * FROM blade_dict WHERE CODE = 'notice') d ON n.category = d.dict_key WHERE n.is_deleted = 0 AND n.tenant_id = ?) TOTAL
Execute Time:0 ms
============== Sql End ==============
2021-03-03 16:39:47.525 DEBUG 16444 --- [ XNIO-1 task-4] o.s.d.m.NoticeMapper.selectNoticePage : ==> Parameters: 000000(String), 10(Long)
============== Sql Start ==============
Execute ID :org.springblade.desk.mapper.NoticeMapper.selectNoticePage
Execute SQL :SELECT n.*, d.dict_value AS categoryName FROM blade_notice n LEFT JOIN (SELECT * FROM blade_dict WHERE CODE = 'notice') d ON n.category = d.dict_key WHERE n.is_deleted = 0 AND n.tenant_id = ? LIMIT ?
Execute Time:4 ms
============== Sql End ==============
2021-03-03 16:39:47.541 DEBUG 16444 --- [ XNIO-1 task-4] o.s.d.m.NoticeMapper.selectNoticePage : <== Total: 5
2021-03-03 16:39:47.543 INFO 16444 --- [ XNIO-1 task-4] o.s.core.log.aspect.RequestLogAspect :
整个sql语句里面,没有出现create_dept 这个字段,也没有出现如文档上面的 create_dept IN 这段sql
二、你期待的结果是什么?实际看到的又是什么?
期待看到纯注解配置数据权限生效,实际没有生效
三、你正在使用的是什么产品,什么版本?在什么操作系统上?
我正在使用bladex2.7.0.RELEASE, 使用的操作系统为windows server2012
超级管理员是不受数据权限插件限制的,你用的是什么帐号
遇到问题可以到这个类打断点看看是为什么没有加上过滤sql
我没有用web配置,是纯注解配置,直接用的postman访问,根本没有登录,这不存在用管理员一说吧
我按照你的要求加了断点,截图如下 mapperSkip里面的值
我这里的account为什么是admin呢,我是通过postman访问的,
根本没有登录系统,为什么account默认的就是admin呢,如果这里要用别的账号怎么做呢
跟踪代码里面的sql如下
跟踪到拦截器这里
红点头的boundsql 语句如下
SELECT n.*, d.dict_value AS categoryName FROM blade_notice n LEFT JOIN (SELECT * FROM blade_dict WHERE CODE = 'notice') d ON n.category = d.dict_key WHERE n.is_deleted = 0 AND n.tenant_id = ?
我知道问题出哪里了
你的思维应该还是以前session时代,认为一定要系统登录了才能取到用户信息。
现在是分布式无状态认证的模式,postman也可以看作和后台系统一样是一个客户端,调用接口的时候带上Blade-Auth请求头,这样每次请求的时候都会对请求头进行解析,获取里面的token,然后再赋值给BladeUser对象。
你postman传递的时候带上了token,自然就会被识别出用户,而从你的截图来看,是admin帐号,所以不会被数据权限拦截。
你想要生效,那就要用其他帐号生成的token测试。
扫一扫访问 Blade技术社区 移动端