mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 09:55:16 +08:00
fix=>权限和租户可以同时忽略,并且可重复忽略,改用栈实现
This commit is contained in:
parent
32743d8a76
commit
28a359836a
@ -13,6 +13,7 @@ import org.dromara.common.core.utils.reflect.ReflectUtils;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +28,7 @@ public class DataPermissionHelper {
|
|||||||
|
|
||||||
private static final String DATA_PERMISSION_KEY = "data:permission";
|
private static final String DATA_PERMISSION_KEY = "data:permission";
|
||||||
|
|
||||||
private static final ThreadLocal<Integer> REENTRANT_IGNORE_PERMISSION = new ThreadLocal<>();
|
private static final Stack<Integer> REENTRANT_IGNORE_PERMISSION_STACK = new Stack<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从上下文中获取指定键的变量值,并将其转换为指定的类型
|
* 从上下文中获取指定键的变量值,并将其转换为指定的类型
|
||||||
@ -77,17 +78,19 @@ public class DataPermissionHelper {
|
|||||||
public static void enableIgnore() {
|
public static void enableIgnore() {
|
||||||
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
||||||
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
||||||
if (Objects.nonNull(ignoreStrategy)) {
|
if (ignoreStrategy == null) {
|
||||||
if (!Boolean.TRUE.equals(ignoreStrategy.getDataPermission())) {
|
|
||||||
ignoreStrategy.setDataPermission(true);
|
|
||||||
REENTRANT_IGNORE_PERMISSION.set(1);
|
|
||||||
} else {
|
|
||||||
Integer count = REENTRANT_IGNORE_PERMISSION.get();
|
|
||||||
REENTRANT_IGNORE_PERMISSION.set(count + 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().dataPermission(true).build());
|
InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().dataPermission(true).build());
|
||||||
REENTRANT_IGNORE_PERMISSION.set(1);
|
REENTRANT_IGNORE_PERMISSION_STACK.push(1);
|
||||||
|
} else {
|
||||||
|
if (Boolean.TRUE.equals(ignoreStrategy.getDataPermission())) {
|
||||||
|
if (REENTRANT_IGNORE_PERMISSION_STACK.isEmpty()) {
|
||||||
|
throw new IllegalStateException("ignore data permission error");
|
||||||
|
}
|
||||||
|
REENTRANT_IGNORE_PERMISSION_STACK.push(REENTRANT_IGNORE_PERMISSION_STACK.peek() + 1);
|
||||||
|
} else {
|
||||||
|
ignoreStrategy.setDataPermission(true);
|
||||||
|
REENTRANT_IGNORE_PERMISSION_STACK.push(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,27 +100,31 @@ public class DataPermissionHelper {
|
|||||||
public static void disableIgnore() {
|
public static void disableIgnore() {
|
||||||
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
||||||
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
||||||
if (Objects.nonNull(ignoreStrategy)) {
|
if (ignoreStrategy != null) {
|
||||||
Integer count = REENTRANT_IGNORE_PERMISSION.get();
|
boolean empty = REENTRANT_IGNORE_PERMISSION_STACK.isEmpty();
|
||||||
boolean hasCount = count.compareTo(1) > 0;
|
int pop = empty ? 1 : REENTRANT_IGNORE_PERMISSION_STACK.pop();
|
||||||
if (ignoreStrategy.getBlockAttack() == null && ignoreStrategy.getDynamicTableName() == null && ignoreStrategy.getTenantLine() == null && ignoreStrategy.getIllegalSql() == null && CollectionUtil.isEmpty(ignoreStrategy.getOthers())) {
|
boolean shouldClear = !Boolean.TRUE.equals(ignoreStrategy.getTenantLine())
|
||||||
if (!hasCount) {
|
&& !Boolean.TRUE.equals(ignoreStrategy.getDynamicTableName())
|
||||||
|
&& !Boolean.TRUE.equals(ignoreStrategy.getBlockAttack())
|
||||||
|
&& !Boolean.TRUE.equals(ignoreStrategy.getIllegalSql())
|
||||||
|
&& CollectionUtil.isEmpty(ignoreStrategy.getOthers());
|
||||||
|
if (shouldClear) {
|
||||||
|
if (empty) {
|
||||||
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
||||||
|
} else {
|
||||||
|
if (pop == 1) {
|
||||||
|
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!hasCount) {
|
if (empty) {
|
||||||
if (count.compareTo(1) == 0) {
|
ignoreStrategy.setDataPermission(false);
|
||||||
ignoreStrategy.setDataPermission(null);
|
} else {
|
||||||
REENTRANT_IGNORE_PERMISSION.remove();
|
if (pop == 1) {
|
||||||
|
ignoreStrategy.setDataPermission(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasCount) {
|
|
||||||
REENTRANT_IGNORE_PERMISSION.set(count - 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
|
||||||
REENTRANT_IGNORE_PERMISSION.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import org.dromara.common.core.utils.reflect.ReflectUtils;
|
|||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Stack;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +32,7 @@ public class TenantHelper {
|
|||||||
|
|
||||||
private static final ThreadLocal<String> TEMP_DYNAMIC_TENANT = new TransmittableThreadLocal<>();
|
private static final ThreadLocal<String> TEMP_DYNAMIC_TENANT = new TransmittableThreadLocal<>();
|
||||||
|
|
||||||
private static final ThreadLocal<Integer> REENTRANT_IGNORE_TENANT = new ThreadLocal<>();
|
private static final Stack<Integer> REENTRANT_IGNORE_TENANT_STACK = new Stack<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户功能是否启用
|
* 租户功能是否启用
|
||||||
@ -47,17 +47,19 @@ public class TenantHelper {
|
|||||||
public static void enableIgnore() {
|
public static void enableIgnore() {
|
||||||
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
||||||
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
||||||
if (Objects.nonNull(ignoreStrategy)) {
|
if (ignoreStrategy == null) {
|
||||||
if (!Boolean.TRUE.equals(ignoreStrategy.getTenantLine())) {
|
|
||||||
ignoreStrategy.setTenantLine(true);
|
|
||||||
REENTRANT_IGNORE_TENANT.set(1);
|
|
||||||
} else {
|
|
||||||
Integer count = REENTRANT_IGNORE_TENANT.get();
|
|
||||||
REENTRANT_IGNORE_TENANT.set(count + 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
|
InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
|
||||||
REENTRANT_IGNORE_TENANT.set(1);
|
REENTRANT_IGNORE_TENANT_STACK.push(1);
|
||||||
|
} else {
|
||||||
|
if (Boolean.TRUE.equals(ignoreStrategy.getTenantLine())) {
|
||||||
|
if (REENTRANT_IGNORE_TENANT_STACK.isEmpty()) {
|
||||||
|
throw new IllegalStateException("ignore tenant error");
|
||||||
|
}
|
||||||
|
REENTRANT_IGNORE_TENANT_STACK.push(REENTRANT_IGNORE_TENANT_STACK.peek() + 1);
|
||||||
|
} else {
|
||||||
|
ignoreStrategy.setTenantLine(true);
|
||||||
|
REENTRANT_IGNORE_TENANT_STACK.push(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,27 +69,31 @@ public class TenantHelper {
|
|||||||
public static void disableIgnore() {
|
public static void disableIgnore() {
|
||||||
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
ThreadLocal<IgnoreStrategy> IGNORE_STRATEGY_LOCAL = (ThreadLocal<IgnoreStrategy>) ReflectUtils.getStaticFieldValue(ReflectUtils.getField(InterceptorIgnoreHelper.class, "IGNORE_STRATEGY_LOCAL"));
|
||||||
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
IgnoreStrategy ignoreStrategy = IGNORE_STRATEGY_LOCAL.get();
|
||||||
if (Objects.nonNull(ignoreStrategy)) {
|
if (ignoreStrategy != null) {
|
||||||
Integer count = REENTRANT_IGNORE_TENANT.get();
|
boolean empty = REENTRANT_IGNORE_TENANT_STACK.isEmpty();
|
||||||
boolean hasCount = count.compareTo(1) > 0;
|
int pop = empty ? 1 : REENTRANT_IGNORE_TENANT_STACK.pop();
|
||||||
if (ignoreStrategy.getBlockAttack() == null && ignoreStrategy.getDynamicTableName() == null && ignoreStrategy.getIllegalSql() == null && ignoreStrategy.getDataPermission() == null && CollectionUtil.isEmpty(ignoreStrategy.getOthers())) {
|
boolean shouldClear = !Boolean.TRUE.equals(ignoreStrategy.getDynamicTableName())
|
||||||
if (!hasCount) {
|
&& !Boolean.TRUE.equals(ignoreStrategy.getBlockAttack())
|
||||||
|
&& !Boolean.TRUE.equals(ignoreStrategy.getIllegalSql())
|
||||||
|
&& !Boolean.TRUE.equals(ignoreStrategy.getDataPermission())
|
||||||
|
&& CollectionUtil.isEmpty(ignoreStrategy.getOthers());
|
||||||
|
if (shouldClear) {
|
||||||
|
if (empty) {
|
||||||
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
||||||
|
} else {
|
||||||
|
if (pop == 1) {
|
||||||
|
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!hasCount) {
|
if (empty) {
|
||||||
if (count.compareTo(1) == 0) {
|
ignoreStrategy.setTenantLine(false);
|
||||||
ignoreStrategy.setTenantLine(null);
|
} else {
|
||||||
REENTRANT_IGNORE_TENANT.remove();
|
if (pop == 1) {
|
||||||
|
ignoreStrategy.setTenantLine(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasCount) {
|
|
||||||
REENTRANT_IGNORE_TENANT.set(count - 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
|
||||||
REENTRANT_IGNORE_TENANT.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user