From 6628ead2eab44a9ce11289e6b54e1223d00ceced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Wed, 16 Apr 2025 10:25:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86satoken=E5=AF=B9dubbo=E5=86=85=E9=83=A8?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E7=9A=84=E6=83=85=E5=86=B5=E8=80=83=E8=99=91?= =?UTF-8?q?=E4=B8=8D=E5=91=A8=20=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8A=E4=B8=8B=E6=96=87=E9=83=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/SaTokenDubbo3ContextFilter.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/cn/dev33/satoken/context/dubbo3/filter/SaTokenDubbo3ContextFilter.java diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/cn/dev33/satoken/context/dubbo3/filter/SaTokenDubbo3ContextFilter.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/cn/dev33/satoken/context/dubbo3/filter/SaTokenDubbo3ContextFilter.java new file mode 100644 index 000000000..3f81b6001 --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/cn/dev33/satoken/context/dubbo3/filter/SaTokenDubbo3ContextFilter.java @@ -0,0 +1,49 @@ +/* + * Copyright 2020-2099 sa-token.cc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.dev33.satoken.context.dubbo3.filter; + +import cn.dev33.satoken.SaManager; +import cn.dev33.satoken.context.SaHolder; +import cn.dev33.satoken.context.dubbo3.util.SaTokenContextDubbo3Util; +import cn.dev33.satoken.util.SaTokenConsts; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.rpc.*; + +/** + * Sa-Token 整合 Dubbo3 上下文初始化过滤器 + * + * @author click33 + * @since 1.42.0 + */ +@Activate(group = {CommonConstants.PROVIDER}, order = SaTokenConsts.RPC_CONTEXT_FILTER_ORDER) +public class SaTokenDubbo3ContextFilter implements Filter { + + @Override + 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(); + } + } + } + +}