mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
feat(sso): 新增 convertCenterIdToLoginId、convertLoginIdToCenterId 策略函数,用于描述本地 LoginId 与认证中心 loginId 的转换规则
This commit is contained in:
@@ -64,7 +64,8 @@ public class SaSsoMessageLogoutCallHandle implements SaSsoMessageHandle {
|
||||
ParamName paramName = ssoClientTemplate.paramName;
|
||||
|
||||
// 获取参数
|
||||
String loginId = req.getParamNotNull(paramName.loginId);
|
||||
Object loginId = req.getParamNotNull(paramName.loginId);
|
||||
loginId = ssoClientTemplate.strategy.convertCenterIdToLoginId.run(loginId);
|
||||
String deviceId = message.getString(paramName.deviceId);
|
||||
|
||||
// 注销当前应用端会话
|
||||
|
||||
@@ -47,6 +47,9 @@ public class SaCheckTicketResult implements Serializable {
|
||||
/** 从 sso-server 返回的所有参数 */
|
||||
public SaResult result;
|
||||
|
||||
/** 此账号在认证中心的 loginId */
|
||||
public Object centerId;
|
||||
|
||||
public SaCheckTicketResult() {
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,8 @@ public class SaSsoClientProcessor {
|
||||
} else {
|
||||
// 1、校验ticket,获取 loginId
|
||||
SaCheckTicketResult ctr = checkTicket(ticket, apiName.ssoLogin);
|
||||
ctr.centerId = ctr.loginId;
|
||||
ctr.loginId = ssoClientTemplate.strategy.convertCenterIdToLoginId.run(ctr.centerId);
|
||||
|
||||
// 2、如果开发者自定义了ticket结果值处理函数,则使用自定义的函数
|
||||
if(ssoClientTemplate.strategy.ticketResultHandle != null) {
|
||||
@@ -230,7 +232,8 @@ public class SaSsoClientProcessor {
|
||||
if(singleDeviceIdLogout) {
|
||||
logoutParameter.setDeviceId(stpLogic.getLoginDeviceId());
|
||||
}
|
||||
SaSsoMessage message = ssoClientTemplate.buildSloMessage(stpLogic.getLoginId(), logoutParameter);
|
||||
Object centerId = ssoClientTemplate.strategy.convertLoginIdToCenterId.run(stpLogic.getLoginId());
|
||||
SaSsoMessage message = ssoClientTemplate.buildSloMessage(centerId, logoutParameter);
|
||||
SaResult result = ssoClientTemplate.pushMessageAsSaResult(message);
|
||||
|
||||
// 校验响应状态码
|
||||
@@ -259,7 +262,8 @@ public class SaSsoClientProcessor {
|
||||
SaSsoClientConfig ssoConfig = ssoClientTemplate.getClientConfig();
|
||||
|
||||
// 获取参数
|
||||
String loginId = req.getParamNotNull(paramName.loginId);
|
||||
Object loginId = req.getParamNotNull(paramName.loginId);
|
||||
loginId = ssoClientTemplate.strategy.convertCenterIdToLoginId.run(loginId);
|
||||
String deviceId = req.getParam(paramName.deviceId);
|
||||
// String client = req.getParam(paramName.client);
|
||||
// String autoLogout = req.getParam(paramName.autoLogout);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package cn.dev33.satoken.sso.strategy;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.fun.SaParamRetFunction;
|
||||
import cn.dev33.satoken.sso.function.SendHttpFunction;
|
||||
import cn.dev33.satoken.sso.function.TicketResultHandleFunction;
|
||||
|
||||
@@ -35,10 +36,30 @@ public class SaSsoClientStrategy {
|
||||
};
|
||||
|
||||
/**
|
||||
* SSO-Client端:自定义校验 ticket 返回值的处理逻辑 (每次从认证中心获取校验 ticket 的结果后调用)
|
||||
* 自定义校验 ticket 返回值的处理逻辑 (每次从认证中心获取校验 ticket 的结果后调用)
|
||||
* <p> 参数:loginId, back
|
||||
* <p> 返回值:返回给前端的值
|
||||
*/
|
||||
public TicketResultHandleFunction ticketResultHandle = null;
|
||||
|
||||
/**
|
||||
* 转换:认证中心 centerId > 本地 loginId
|
||||
*
|
||||
* <p> 参数:认证中心 centerId
|
||||
* <p> 返回值:本地 loginId
|
||||
*/
|
||||
public SaParamRetFunction<Object, Object> convertCenterIdToLoginId = (centerId) -> {
|
||||
return centerId;
|
||||
};
|
||||
|
||||
/**
|
||||
* 转换:本地 loginId > 认证中心 centerId
|
||||
*
|
||||
* <p> 参数:本地 loginId
|
||||
* <p> 返回值:认证中心 centerId
|
||||
*/
|
||||
public SaParamRetFunction<Object, Object> convertLoginIdToCenterId = (loginId) -> {
|
||||
return loginId;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user