♻️ 重构代码
This commit is contained in:
1 parent
4de4f6c349
commit
ea6072eb4a
19 files changed
+125
-106
No files matched your search
+3
-3
@@ -18,7 +18,7 @@
|
||||
package com.pig4cloud.pigx.common.security.feign;
|
||||
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import com.pig4cloud.pigx.common.core.util.TenantUtils;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -31,10 +31,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class PigxFeignTenantInterceptor implements RequestInterceptor {
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
if (SecurityUtils.getTenantId() == null) {
|
||||
if (TenantUtils.getTenantId() == null) {
|
||||
log.error("TTL 中的 租户ID为空,feign拦截器 >> 增强失败");
|
||||
return;
|
||||
}
|
||||
requestTemplate.header(CommonConstant.TENANT_ID, SecurityUtils.getTenantId().toString());
|
||||
requestTemplate.header(CommonConstant.TENANT_ID, TenantUtils.getTenantId().toString());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -19,7 +19,7 @@ package com.pig4cloud.pigx.common.security.filter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import com.pig4cloud.pigx.common.core.util.TenantUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -52,9 +52,9 @@ public class TenantIdTtlFilter extends GenericFilterBean {
|
||||
log.debug("获取header中的租户ID为:{}", tenantId);
|
||||
|
||||
if (StrUtil.isNotBlank(tenantId)) {
|
||||
SecurityUtils.setTenantId(Integer.parseInt(tenantId));
|
||||
TenantUtils.setTenantId(Integer.parseInt(tenantId));
|
||||
} else {
|
||||
SecurityUtils.setTenantId(1);
|
||||
TenantUtils.setTenantId(1);
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
|
||||
-20
@@ -21,7 +21,6 @@ package com.pig4cloud.pigx.common.security.util;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.security.service.PigxUser;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -39,8 +38,6 @@ import java.util.List;
|
||||
* @author L.cm
|
||||
*/
|
||||
public class SecurityUtils {
|
||||
private static final ThreadLocal<Integer> THREAD_LOCAL_TENANT = new TransmittableThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 获取Authentication
|
||||
*/
|
||||
@@ -121,21 +118,4 @@ public class SecurityUtils {
|
||||
return roleIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* TTL 设置租户ID
|
||||
*
|
||||
* @param tenantId
|
||||
*/
|
||||
public static void setTenantId(Integer tenantId) {
|
||||
THREAD_LOCAL_TENANT.set(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取TTL中的租户ID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Integer getTenantId() {
|
||||
return THREAD_LOCAL_TENANT.get();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user