mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-08-01 10:10:09 +08:00
优化 sa-token-context-dubbo 模块注释
This commit is contained in:
parent
93e01042d6
commit
7377df3408
@ -4,10 +4,10 @@ import cn.dev33.satoken.context.second.SaTokenSecondContext;
|
|||||||
import cn.dev33.satoken.context.second.SaTokenSecondContextCreator;
|
import cn.dev33.satoken.context.second.SaTokenSecondContextCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sa-Token 二级Context - 创建器 [Dubbo版]
|
* Sa-Token 二级上下文 - 创建器 [ Dubbo版 ]
|
||||||
*
|
*
|
||||||
* @author click33
|
* @author click33
|
||||||
*
|
* @since <= 1.34.0
|
||||||
*/
|
*/
|
||||||
public class SaTokenSecondContextCreatorForDubbo implements SaTokenSecondContextCreator {
|
public class SaTokenSecondContextCreatorForDubbo implements SaTokenSecondContextCreator {
|
||||||
|
|
||||||
|
@ -12,10 +12,10 @@ import cn.dev33.satoken.context.second.SaTokenSecondContext;
|
|||||||
import cn.dev33.satoken.exception.ApiDisabledException;
|
import cn.dev33.satoken.exception.ApiDisabledException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sa-Token 上下文 [Dubbo版本]
|
* Sa-Token 二级上下文 [ Dubbo版本 ]
|
||||||
*
|
*
|
||||||
* @author click33
|
* @author click33
|
||||||
*
|
* @since <= 1.34.0
|
||||||
*/
|
*/
|
||||||
public class SaTokenSecondContextForDubbo implements SaTokenSecondContext {
|
public class SaTokenSecondContextForDubbo implements SaTokenSecondContext {
|
||||||
|
|
||||||
|
@ -16,11 +16,10 @@ import cn.dev33.satoken.stp.StpUtil;
|
|||||||
import cn.dev33.satoken.util.SaTokenConsts;
|
import cn.dev33.satoken.util.SaTokenConsts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Sa-Token 整合 Dubbo Consumer 端(调用端)过滤器
|
||||||
* Sa-Token 整合 Dubbo Consumer端过滤器
|
|
||||||
*
|
*
|
||||||
* @author click33
|
* @author click33
|
||||||
*
|
* @since <= 1.34.0
|
||||||
*/
|
*/
|
||||||
@Activate(group = {CommonConstants.CONSUMER}, order = -30000)
|
@Activate(group = {CommonConstants.CONSUMER}, order = -30000)
|
||||||
public class SaTokenDubboConsumerFilter implements Filter {
|
public class SaTokenDubboConsumerFilter implements Filter {
|
||||||
@ -28,23 +27,23 @@ public class SaTokenDubboConsumerFilter implements Filter {
|
|||||||
@Override
|
@Override
|
||||||
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||||
|
|
||||||
// 追加 Same-Token 参数
|
// 1、追加 Same-Token 参数
|
||||||
if(SaManager.getConfig().getCheckSameToken()) {
|
if(SaManager.getConfig().getCheckSameToken()) {
|
||||||
RpcContext.getContext().setAttachment(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken());
|
RpcContext.getContext().setAttachment(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. 调用前,向下传递会话Token
|
// 2、调用前,向下传递会话Token
|
||||||
if(SaManager.getSaTokenContextOrSecond() != SaTokenContextDefaultImpl.defaultContext) {
|
if(SaManager.getSaTokenContextOrSecond() != SaTokenContextDefaultImpl.defaultContext) {
|
||||||
RpcContext.getContext().setAttachment(SaTokenConsts.JUST_CREATED, StpUtil.getTokenValueNotCut());
|
RpcContext.getContext().setAttachment(SaTokenConsts.JUST_CREATED, StpUtil.getTokenValueNotCut());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 开始调用
|
// 3、开始调用
|
||||||
Result invoke = invoker.invoke(invocation);
|
Result invoke = invoker.invoke(invocation);
|
||||||
|
|
||||||
// 3. 调用后,解析回传的Token值
|
// 4、调用后,解析回传的Token值
|
||||||
StpUtil.setTokenValue(invoke.getAttachment(SaTokenConsts.JUST_CREATED_NOT_PREFIX));
|
StpUtil.setTokenValue(invoke.getAttachment(SaTokenConsts.JUST_CREATED_NOT_PREFIX));
|
||||||
|
|
||||||
// note
|
// 5、返回结果
|
||||||
return invoke;
|
return invoke;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,11 +12,10 @@ import cn.dev33.satoken.SaManager;
|
|||||||
import cn.dev33.satoken.same.SaSameUtil;
|
import cn.dev33.satoken.same.SaSameUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Sa-Token 整合 Dubbo Provider端(被调用端)过滤器
|
||||||
* Sa-Token 整合 Dubbo Provider端过滤器
|
|
||||||
*
|
*
|
||||||
* @author click33
|
* @author click33
|
||||||
*
|
* @since <= 1.34.0
|
||||||
*/
|
*/
|
||||||
@Activate(group = {CommonConstants.PROVIDER}, order = -30000)
|
@Activate(group = {CommonConstants.PROVIDER}, order = -30000)
|
||||||
public class SaTokenDubboProviderFilter implements Filter {
|
public class SaTokenDubboProviderFilter implements Filter {
|
||||||
@ -27,7 +26,8 @@ public class SaTokenDubboProviderFilter implements Filter {
|
|||||||
// RPC 调用鉴权
|
// RPC 调用鉴权
|
||||||
if(SaManager.getConfig().getCheckSameToken()) {
|
if(SaManager.getConfig().getCheckSameToken()) {
|
||||||
String idToken = invocation.getAttachment(SaSameUtil.SAME_TOKEN);
|
String idToken = invocation.getAttachment(SaSameUtil.SAME_TOKEN);
|
||||||
// dubbo部分协议会将参数变为小写,详细参考:https://gitee.com/dromara/sa-token/issues/I4WXQG
|
|
||||||
|
// dubbo部分协议会将参数变为小写,此处需要额外处理一下,详细参考:https://gitee.com/dromara/sa-token/issues/I4WXQG
|
||||||
if(idToken == null) {
|
if(idToken == null) {
|
||||||
idToken = invocation.getAttachment(SaSameUtil.SAME_TOKEN.toLowerCase());
|
idToken = invocation.getAttachment(SaSameUtil.SAME_TOKEN.toLowerCase());
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
package cn.dev33.satoken.context.dubbo.model;
|
package cn.dev33.satoken.context.dubbo.model;
|
||||||
|
|
||||||
import org.apache.dubbo.rpc.RpcContext;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.context.model.SaRequest;
|
import cn.dev33.satoken.context.model.SaRequest;
|
||||||
|
import org.apache.dubbo.rpc.RpcContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request for Dubbo
|
* 对 SaRequest 包装类的实现(Dubbo 版)
|
||||||
*
|
|
||||||
* @author click33
|
|
||||||
*
|
*
|
||||||
|
* @author click33
|
||||||
|
* @since <= 1.34.0
|
||||||
*/
|
*/
|
||||||
public class SaRequestForDubbo implements SaRequest {
|
public class SaRequestForDubbo implements SaRequest {
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package cn.dev33.satoken.context.dubbo.model;
|
package cn.dev33.satoken.context.dubbo.model;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.context.model.SaResponse;
|
||||||
import org.apache.dubbo.rpc.RpcContext;
|
import org.apache.dubbo.rpc.RpcContext;
|
||||||
|
|
||||||
import cn.dev33.satoken.context.model.SaResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response for Servlet
|
* 对 SaResponse 包装类的实现(Dubbo 版)
|
||||||
* @author click33
|
|
||||||
*
|
*
|
||||||
|
* @author click33
|
||||||
|
* @since <= 1.34.0
|
||||||
*/
|
*/
|
||||||
public class SaResponseForDubbo implements SaResponse {
|
public class SaResponseForDubbo implements SaResponse {
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package cn.dev33.satoken.context.dubbo.model;
|
package cn.dev33.satoken.context.dubbo.model;
|
||||||
|
|
||||||
import org.apache.dubbo.rpc.RpcContext;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.context.model.SaStorage;
|
import cn.dev33.satoken.context.model.SaStorage;
|
||||||
import cn.dev33.satoken.util.SaTokenConsts;
|
import cn.dev33.satoken.util.SaTokenConsts;
|
||||||
|
import org.apache.dubbo.rpc.RpcContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage for Servlet
|
* 对 SaStorage 包装类的实现(Dubbo 版)
|
||||||
* @author click33
|
|
||||||
*
|
*
|
||||||
|
* @author click33
|
||||||
|
* @since <= 1.34.0
|
||||||
*/
|
*/
|
||||||
public class SaStorageForDubbo implements SaStorage {
|
public class SaStorageForDubbo implements SaStorage {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user