mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-06-28 04:35:16 +08:00
fix: 修复 sa-token-dubbo 与 sa-token-dubbo3 每次调用都强制需要上下文的问题。
This commit is contained in:
parent
0cd3d66712
commit
e80369eb4b
@ -16,6 +16,7 @@
|
||||
package cn.dev33.satoken.context.dubbo.filter;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.SaTokenContextDefaultImpl;
|
||||
import cn.dev33.satoken.same.SaSameUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@ -36,23 +37,28 @@ public class SaTokenDubboConsumerFilter implements Filter {
|
||||
@Override
|
||||
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||
|
||||
// 1、追加 Same-Token 参数
|
||||
// 追加 Same-Token 参数
|
||||
if(SaManager.getConfig().getCheckSameToken()) {
|
||||
RpcContext.getContext().setAttachment(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken());
|
||||
}
|
||||
|
||||
// 2、调用前,向下传递会话Token
|
||||
|
||||
// 无上下文时只做简单调用,不传递会话 token
|
||||
if( ! SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
}
|
||||
|
||||
// 1、调用前,向下传递会话Token
|
||||
if(SaManager.getSaTokenContext() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
RpcContext.getContext().setAttachment(SaTokenConsts.JUST_CREATED, StpUtil.getTokenValueNotCut());
|
||||
}
|
||||
|
||||
// 3、开始调用
|
||||
// 2、开始调用
|
||||
Result invoke = invoker.invoke(invocation);
|
||||
|
||||
// 4、调用后,解析回传的Token值
|
||||
// 3、调用后,解析回传的Token值
|
||||
StpUtil.setTokenValue(invoke.getAttachment(SaTokenConsts.JUST_CREATED_NOT_PREFIX));
|
||||
|
||||
// 5、返回结果
|
||||
// note
|
||||
return invoke;
|
||||
}
|
||||
|
||||
|
@ -36,13 +36,12 @@ public class SaTokenDubboContextFilter implements Filter {
|
||||
public Result invoke(Invoker<?> invoker, Invocation invocation) {
|
||||
if(SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
} else {
|
||||
try {
|
||||
SaTokenContextDubboUtil.setContext(RpcContext.getContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
}
|
||||
try {
|
||||
SaTokenContextDubboUtil.setContext(RpcContext.getContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
package cn.dev33.satoken.context.dubbo3.filter;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.SaTokenContextDefaultImpl;
|
||||
import cn.dev33.satoken.same.SaSameUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@ -40,6 +41,11 @@ public class SaTokenDubbo3ConsumerFilter implements Filter {
|
||||
if(SaManager.getConfig().getCheckSameToken()) {
|
||||
RpcContext.getServiceContext().setAttachment(SaSameUtil.SAME_TOKEN,SaSameUtil.getToken());
|
||||
}
|
||||
|
||||
// 无上下文时只做简单调用,不传递会话 token
|
||||
if( ! SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
}
|
||||
|
||||
// 1. 调用前,向下传递会话Token
|
||||
if(SaManager.getSaTokenContext() != SaTokenContextDefaultImpl.defaultContext) {
|
||||
|
@ -36,14 +36,14 @@ public class SaTokenDubbo3ContextFilter implements Filter {
|
||||
public Result invoke(Invoker<?> invoker, Invocation invocation) {
|
||||
if(SaHolder.getContext().isValid()) {
|
||||
return invoker.invoke(invocation);
|
||||
} else {
|
||||
try {
|
||||
SaTokenContextDubbo3Util.setContext(RpcContext.getServiceContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
}
|
||||
try {
|
||||
SaTokenContextDubbo3Util.setContext(RpcContext.getServiceContext());
|
||||
return invoker.invoke(invocation);
|
||||
} finally {
|
||||
SaManager.getSaTokenContext().clearContext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user