refactor: 重构所有 starter 组件的 SaTokenContext 上下文读写策略
This commit is contained in:
+1
-8
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package cn.dev33.satoken.context.dubbo;
|
||||
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
|
||||
import cn.dev33.satoken.context.dubbo.model.SaRequestForDubbo;
|
||||
import cn.dev33.satoken.context.dubbo.model.SaResponseForDubbo;
|
||||
import cn.dev33.satoken.context.dubbo.model.SaStorageForDubbo;
|
||||
@@ -24,7 +22,7 @@ import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
import cn.dev33.satoken.context.second.SaTokenSecondContext;
|
||||
import cn.dev33.satoken.exception.ApiDisabledException;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* Sa-Token 二级上下文 [ Dubbo版本 ]
|
||||
@@ -49,11 +47,6 @@ public class SaTokenSecondContextForDubbo implements SaTokenSecondContext {
|
||||
return new SaStorageForDubbo(RpcContext.getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchPath(String pattern, String path) {
|
||||
throw new ApiDisabledException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return RpcContext.getContext() != null;
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class SaTokenDubboConsumerFilter implements Filter {
|
||||
}
|
||||
|
||||
// 2、调用前,向下传递会话Token
|
||||
if(SaManager.getSaTokenContextOrSecond() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
if(SaManager.getSaTokenContext() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
RpcContext.getContext().setAttachment(SaTokenConsts.JUST_CREATED, StpUtil.getTokenValueNotCut());
|
||||
}
|
||||
|
||||
|
||||
-6
@@ -22,7 +22,6 @@ import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
import cn.dev33.satoken.context.second.SaTokenSecondContext;
|
||||
import cn.dev33.satoken.exception.ApiDisabledException;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
@@ -48,11 +47,6 @@ public class SaTokenSecondContextForDubbo3 implements SaTokenSecondContext {
|
||||
return new SaStorageForDubbo3(RpcContext.getServiceContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchPath(String pattern, String path) {
|
||||
throw new ApiDisabledException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return RpcContext.getServiceContext() != null;
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class SaTokenDubbo3ConsumerFilter implements Filter {
|
||||
}
|
||||
|
||||
// 1. 调用前,向下传递会话Token
|
||||
if(SaManager.getSaTokenContextOrSecond() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
if(SaManager.getSaTokenContext() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
RpcContext.getServiceContext().setAttachment(SaTokenConsts.JUST_CREATED, StpUtil.getTokenValueNotCut());
|
||||
}
|
||||
|
||||
|
||||
-6
@@ -23,7 +23,6 @@ import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
import cn.dev33.satoken.context.second.SaTokenSecondContext;
|
||||
import cn.dev33.satoken.exception.ApiDisabledException;
|
||||
|
||||
/**
|
||||
* Sa-Token 上下文 [grpc版本]
|
||||
@@ -48,11 +47,6 @@ public class SaTokenSecondContextForGrpc implements SaTokenSecondContext {
|
||||
return new SaStorageForGrpc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchPath(String pattern, String path) {
|
||||
throw new ApiDisabledException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return SaTokenGrpcContext.isNotNull();
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class SaTokenGrpcClientInterceptor implements ClientInterceptor, Ordered
|
||||
// 调用前,传递会话Token
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
if (SaFoxUtil.isNotEmpty(tokenValue)
|
||||
&& SaManager.getSaTokenContextOrSecond() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
&& SaManager.getSaTokenContext() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
headers.put(GrpcContextConstants.SA_JUST_CREATED_NOT_PREFIX, tokenValue);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user