|
|
@@ -5,6 +5,7 @@ import com.fs.common.enums.DataSourceType;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.config.saas.ProjectConfig;
|
|
|
import com.fs.core.config.TenantConfigContext;
|
|
|
+import com.fs.framework.config.TenantPrincipal;
|
|
|
import com.fs.framework.datasource.DynamicDataSourceContextHolder;
|
|
|
import com.fs.framework.datasource.TenantDataSourceManager;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
@@ -13,11 +14,14 @@ import com.fs.tenant.domain.TenantInfo;
|
|
|
import com.fs.tenant.service.TenantInfoService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.PreDestroy;
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.*;
|
|
|
@@ -180,6 +184,16 @@ public class TenantTaskRunner {
|
|
|
}
|
|
|
ProjectConfig.loadTenantConfigsFromContext();
|
|
|
action.accept(tenant);
|
|
|
+
|
|
|
+ // 设置租户到 SecurityContext,供 TenantKeyRedisSerializer 自动为 Redis Key 加 tenantid 前缀
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(
|
|
|
+ new UsernamePasswordAuthenticationToken(
|
|
|
+ new TenantPrincipal(tenant.getId()),
|
|
|
+ null,
|
|
|
+ Collections.emptyList()
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("[SaaS Task] 租户 tenantId={}, tenantCode={} 执行异常", tenant.getId(), tenant.getTenantCode(), e);
|
|
|
} finally {
|