Commit 81d21b0d authored by tianbo's avatar tianbo

数据权限拦截器优化

parent f87ef47f
...@@ -79,26 +79,13 @@ public class PermissionInterceptor implements Interceptor { ...@@ -79,26 +79,13 @@ public class PermissionInterceptor implements Interceptor {
if(!ValidationUtil.isEmpty(dataAuth)){ if(!ValidationUtil.isEmpty(dataAuth)){
dataAuthRule = !ValidationUtil.isEmpty(dataAuthRule) ? dataAuthRule : dataAuth.interfacePath(); dataAuthRule = !ValidationUtil.isEmpty(dataAuthRule) ? dataAuthRule : dataAuth.interfacePath();
} }
// 数据权限地址为空返回空数据
if(ValidationUtil.isEmpty(dataAuthRule)){
// method.getReturnType().isPrimitive() = true 是count语句
PermissionInterceptorContext.clean();
return method.getReturnType().isPrimitive() ? invocation.proceed() : null;
}
ReginParams reginParam = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId() ReginParams reginParam = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId()
, RequestContext.getToken())).toString(), ReginParams.class); , RequestContext.getToken())).toString(), ReginParams.class);
if (ValidationUtil.isEmpty(reginParam) || ValidationUtil.isEmpty(reginParam.getUserModel())) {
// method.getReturnType().isPrimitive() = true 是count语句
PermissionInterceptorContext.clean();
return method.getReturnType().isPrimitive() ? invocation.proceed() : null;
}
// 用户数据权限配置信息 // 用户数据权限配置信息
Map<String, List<PermissionDataruleModel>> dataAuthorization = Privilege.permissionDataruleClient.queryByUser(reginParam.getUserModel().getUserId(), Map<String, List<PermissionDataruleModel>> dataAuthorization = null;
if (!ValidationUtil.isEmpty(reginParam) && !ValidationUtil.isEmpty(reginParam.getUserModel())) {
dataAuthorization = Privilege.permissionDataruleClient.queryByUser(reginParam.getUserModel().getUserId(),
dataAuthRule).getResult(); dataAuthRule).getResult();
// 没有数据权限直接返回空数据
if (ValidationUtil.isEmpty(dataAuthorization)) {
PermissionInterceptorContext.clean();
return method.getReturnType().isPrimitive() ? invocation.proceed() : null;
} }
BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql"); BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
...@@ -194,6 +181,9 @@ public class PermissionInterceptor implements Interceptor { ...@@ -194,6 +181,9 @@ public class PermissionInterceptor implements Interceptor {
mainTable : selectBody.getFromItem().getAlias().getName(); mainTable : selectBody.getFromItem().getAlias().getName();
String authSql; String authSql;
if (ValidationUtil.isEmpty(dataAuthorization)) {
authSql = falseCondition;
} else {
// 过滤没有配置数据权限的用户组 // 过滤没有配置数据权限的用户组
Map<String, List<PermissionDataruleModel>> nonEmptyDataAuthorization = Map<String, List<PermissionDataruleModel>> nonEmptyDataAuthorization =
dataAuthorization.entrySet().stream().filter(map -> !ValidationUtil.isEmpty(map.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); dataAuthorization.entrySet().stream().filter(map -> !ValidationUtil.isEmpty(map.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
...@@ -204,6 +194,7 @@ public class PermissionInterceptor implements Interceptor { ...@@ -204,6 +194,7 @@ public class PermissionInterceptor implements Interceptor {
// 解析数据权限sql // 解析数据权限sql
authSql = parseDataAuthorization(nonEmptyDataAuthorization, reginParams, mainTableAlias, boundSql); authSql = parseDataAuthorization(nonEmptyDataAuthorization, reginParams, mainTableAlias, boundSql);
} }
}
// 替换数据权限 // 替换数据权限
if (!ValidationUtil.isEmpty(authSql)) { if (!ValidationUtil.isEmpty(authSql)) {
if (ValidationUtil.isEmpty(selectBody.getWhere())) { if (ValidationUtil.isEmpty(selectBody.getWhere())) {
......
...@@ -2041,12 +2041,12 @@ ...@@ -2041,12 +2041,12 @@
<!-- <if test="orgCode != null">--> <!-- <if test="orgCode != null">-->
<!-- AND c.org_code = #{orgCode}--> <!-- AND c.org_code = #{orgCode}-->
<!-- </if>--> <!-- </if>-->
</where>
ORDER BY c.check_time DESC ORDER BY c.check_time DESC
<choose> <choose>
<when test="pageSize==-1"></when> <when test="pageSize==-1"></when>
<when test="pageSize!=-1">limit #{offset},#{pageSize}</when> <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>
</choose> </choose>
</where>
</select> </select>
<select id="getCheckListByTaskId" resultType="com.yeejoin.amos.supervision.dao.entity.Check"> <select id="getCheckListByTaskId" resultType="com.yeejoin.amos.supervision.dao.entity.Check">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment