fix 修复 解决dubbo获取元数据satoken优先级过低 内网鉴权报错问题
parent
3f2a2b8b01
commit
1a34da9625
|
|
@ -47,6 +47,12 @@
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||||
|
<version>${satoken.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Sa-Token 整合 Dubbo -->
|
<!-- Sa-Token 整合 Dubbo -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package cn.dev33.satoken.context.dubbo.filter;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.SaManager;
|
||||||
|
import cn.dev33.satoken.context.SaTokenContextDefaultImpl;
|
||||||
|
import cn.dev33.satoken.id.SaIdUtil;
|
||||||
|
import cn.dev33.satoken.spring.SaBeanInject;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.dev33.satoken.util.SaTokenConsts;
|
||||||
|
import com.ruoyi.common.core.utils.SpringUtils;
|
||||||
|
import org.apache.dubbo.common.constants.CommonConstants;
|
||||||
|
import org.apache.dubbo.common.extension.Activate;
|
||||||
|
import org.apache.dubbo.rpc.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Sa-Token 整合 Dubbo Consumer端过滤器
|
||||||
|
*
|
||||||
|
* 此过滤器为覆盖 Sa-Token 包内过滤器
|
||||||
|
*
|
||||||
|
* @author kong
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Activate(group = {CommonConstants.CONSUMER}, order = Integer.MIN_VALUE)
|
||||||
|
public class SaTokenDubboConsumerFilter implements Filter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||||
|
// 强制初始化 Sa-Token 相关配置 解决内网鉴权元数据加载报错问题
|
||||||
|
SpringUtils.getBean(SaBeanInject.class);
|
||||||
|
|
||||||
|
// 追加 Id-Token 参数
|
||||||
|
if(SaManager.getConfig().getCheckIdToken()) {
|
||||||
|
RpcContext.getContext().setAttachment(SaIdUtil.ID_TOKEN, SaIdUtil.getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 调用前,向下传递会话Token
|
||||||
|
if(SaManager.getSaTokenContextOrSecond() != SaTokenContextDefaultImpl.defaultContext) {
|
||||||
|
RpcContext.getContext().setAttachment(SaTokenConsts.JUST_CREATED, StpUtil.getTokenValueNotCut());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 开始调用
|
||||||
|
Result invoke = invoker.invoke(invocation);
|
||||||
|
|
||||||
|
// 3. 调用后,解析回传的Token值
|
||||||
|
StpUtil.setTokenValue(invoke.getAttachment(SaTokenConsts.JUST_CREATED_NOT_PREFIX));
|
||||||
|
|
||||||
|
// note
|
||||||
|
return invoke;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package cn.dev33.satoken.context.dubbo.filter;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.SaManager;
|
||||||
|
import cn.dev33.satoken.id.SaIdUtil;
|
||||||
|
import cn.dev33.satoken.spring.SaBeanInject;
|
||||||
|
import com.ruoyi.common.core.utils.SpringUtils;
|
||||||
|
import org.apache.dubbo.common.constants.CommonConstants;
|
||||||
|
import org.apache.dubbo.common.extension.Activate;
|
||||||
|
import org.apache.dubbo.rpc.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Sa-Token 整合 Dubbo Provider端过滤器
|
||||||
|
*
|
||||||
|
* 此过滤器为覆盖 Sa-Token 包内过滤器
|
||||||
|
*
|
||||||
|
* @author kong
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Activate(group = {CommonConstants.PROVIDER}, order = Integer.MIN_VALUE)
|
||||||
|
public class SaTokenDubboProviderFilter implements Filter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||||
|
// 强制初始化 Sa-Token 相关配置 解决内网鉴权元数据加载报错问题
|
||||||
|
SpringUtils.getBean(SaBeanInject.class);
|
||||||
|
|
||||||
|
// RPC 调用鉴权
|
||||||
|
if(SaManager.getConfig().getCheckIdToken()) {
|
||||||
|
String idToken = invocation.getAttachment(SaIdUtil.ID_TOKEN);
|
||||||
|
SaIdUtil.checkToken(idToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始调用
|
||||||
|
return invoker.invoke(invocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue