Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: infra支持Hbase文件存储格式 + 数据权限针对共享数据做数据权限划分过滤 + SecurityFrameworkServiceImpl异步线程隔离LoadingCache #200

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions yudao-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<commons-io.version>2.17.0</commons-io.version>
<commons-compress.version>1.27.1</commons-compress.version>
<aws-java-sdk-s3.version>1.12.777</aws-java-sdk-s3.version>
<hbase-client.version>2.6.0</hbase-client.version>
<justauth.version>1.0.8</justauth.version>
<jimureport.version>1.7.8</jimureport.version>
<weixin-java.version>4.6.0</weixin-java.version>
Expand Down Expand Up @@ -639,6 +640,13 @@
<version>${aws-java-sdk-s3.version}</version>
</dependency>

<!--hbase-client-->
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>${hbase-client.version}</version>
</dependency>

<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-pay</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.cache.LoadingCache;

import java.time.Duration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
Expand Down Expand Up @@ -35,6 +36,27 @@ public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration durati
.build(CacheLoader.asyncReloading(loader, Executors.newCachedThreadPool())); // TODO 芋艿:可能要思考下,未来要不要做成可配置
}

/**
* 构建异步刷新的 LoadingCache 对象 线程安全
* 注意:如果你的缓存和 ThreadLocal 有关系,要么自己处理 ThreadLocal 的传递,要么使用 {@link #buildCache(Duration, CacheLoader)} 方法
*
* 或者简单理解:
* 1、和“人”相关的,使用 {@link #buildCache(Duration, CacheLoader)} 方法
* 2、和“全局”、“系统”相关的,使用当前缓存方法
*
* @param duration 过期时间
* @param loader CacheLoader 对象
* @return LoadingCache 对象
*/
public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration duration, CacheLoader<K, V> loader, ExecutorService executor) {
return CacheBuilder.newBuilder()
// 只阻塞当前数据加载线程,其他线程返回旧值
.refreshAfterWrite(duration)
// 通过 asyncReloading 实现全异步加载,包括 refreshAfterWrite 被阻塞的加载线程
// 由于此处 无法直接传入 security 里的类 ExecutorService 此处作为参数传入
.build(CacheLoader.asyncReloading(loader, executor));
}

/**
* 构建同步刷新的 LoadingCache 对象
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.datapermission.core.rule.dept.DeptDataPermissionRule;
import cn.iocoder.yudao.framework.datapermission.core.rule.dept.DeptDataPermissionRuleCustomizer;
import cn.iocoder.yudao.framework.datapermission.core.rule.dept_new.CommonDataPermissionRule;
import cn.iocoder.yudao.framework.datapermission.core.rule.dept_new.CommonDataPermissionRuleCustomizer;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.tenant.TenantApi;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -19,10 +22,11 @@
*/
@AutoConfiguration
@ConditionalOnClass(LoginUser.class)
@ConditionalOnBean(value = DeptDataPermissionRuleCustomizer.class)
// @ConditionalOnBean(value = DeptDataPermissionRuleCustomizer.class)
public class YudaoDeptDataPermissionAutoConfiguration {

@Bean
@ConditionalOnBean(value = {DeptDataPermissionRuleCustomizer.class})
public DeptDataPermissionRule deptDataPermissionRule(PermissionApi permissionApi,
List<DeptDataPermissionRuleCustomizer> customizers) {
// Cloud 专属逻辑:优先使用本地的 PermissionApi 实现类,而不是 Feign 调用
Expand All @@ -41,4 +45,28 @@ public DeptDataPermissionRule deptDataPermissionRule(PermissionApi permissionApi
return rule;
}


@Bean
@ConditionalOnBean(value = {CommonDataPermissionRuleCustomizer.class})
public CommonDataPermissionRule deptDataPermissionRuleTwo(PermissionApi permissionApi,
List<CommonDataPermissionRuleCustomizer> customizers) {
// Cloud 专属逻辑:优先使用本地的 PermissionApi 实现类,而不是 Feign 调用
// 原因:在创建租户时,租户还没创建好,导致 Feign 调用获取数据权限时,报“租户不存在”的错误
// 为了和上面保持方法一致
TenantApi tenantApiImpl = null;
try {
PermissionApi permissionApiImpl = SpringUtil.getBean("permissionApiImpl", PermissionApi.class);
tenantApiImpl = SpringUtil.getBean("tenantApi", TenantApi.class);
if (permissionApiImpl != null) {
permissionApi = permissionApiImpl;
}
} catch (Exception ignored) {}

// 创建 DeptDataPermissionTwoRule 对象
CommonDataPermissionRule rule = new CommonDataPermissionRule(permissionApi, tenantApiImpl);
// 补全表配置
customizers.forEach(customizer -> customizer.customize(rule));
return rule;
}

}
Loading