mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-05-14 12:52:08 +08:00
feat(sso): 单点注销消息推送时忽略掉发起调用的 client,减少不必要的调用
This commit is contained in:
@@ -79,7 +79,7 @@ SaSsoServerUtil.checkRedirectUrl(String client, String url);
|
|||||||
SaSsoServerUtil.ssoLogout(Object loginId);
|
SaSsoServerUtil.ssoLogout(Object loginId);
|
||||||
|
|
||||||
// 指定账号单点注销
|
// 指定账号单点注销
|
||||||
SaSsoServerUtil.ssoLogout(Object loginId, SaLogoutParameter logoutParameter);
|
SaSsoServerUtil.ssoLogout(Object loginId, SaLogoutParameter logoutParameter, String ignoreClient);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,13 @@ public class SaSsoMessageSignoutHandle implements SaSsoMessageHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3、获取参数
|
// 3、获取参数
|
||||||
|
String client = message.getString(paramName.client);
|
||||||
Object loginId = message.get(paramName.loginId);
|
Object loginId = message.get(paramName.loginId);
|
||||||
String deviceId = message.getString(paramName.deviceId);
|
String deviceId = message.getString(paramName.deviceId);
|
||||||
|
|
||||||
// 4、单点注销
|
// 4、单点注销
|
||||||
SaLogoutParameter logoutParameter = ssoServerTemplate.getStpLogicOrGlobal().createSaLogoutParameter().setDeviceId(deviceId);
|
SaLogoutParameter logoutParameter = ssoServerTemplate.getStpLogicOrGlobal().createSaLogoutParameter().setDeviceId(deviceId);
|
||||||
ssoServerTemplate.ssoLogout(loginId, logoutParameter);
|
ssoServerTemplate.ssoLogout(loginId, logoutParameter, client);
|
||||||
|
|
||||||
// 5、响应
|
// 5、响应
|
||||||
return SaResult.ok();
|
return SaResult.ok();
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ public class SaSsoServerProcessor {
|
|||||||
if(singleDeviceIdLogout) {
|
if(singleDeviceIdLogout) {
|
||||||
logoutParameter.setDeviceId(stpLogic.getLoginDeviceId());
|
logoutParameter.setDeviceId(stpLogic.getLoginDeviceId());
|
||||||
}
|
}
|
||||||
ssoServerTemplate.ssoLogout(loginId, logoutParameter);
|
ssoServerTemplate.ssoLogout(loginId, logoutParameter, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 完成
|
// 完成
|
||||||
|
|||||||
@@ -573,7 +573,7 @@ public class SaSsoServerTemplate extends SaSsoTemplate {
|
|||||||
* @param loginId 指定账号
|
* @param loginId 指定账号
|
||||||
*/
|
*/
|
||||||
public void ssoLogout(Object loginId) {
|
public void ssoLogout(Object loginId) {
|
||||||
ssoLogout(loginId, getStpLogicOrGlobal().createSaLogoutParameter());
|
ssoLogout(loginId, getStpLogicOrGlobal().createSaLogoutParameter(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -581,11 +581,12 @@ public class SaSsoServerTemplate extends SaSsoTemplate {
|
|||||||
*
|
*
|
||||||
* @param loginId 指定账号
|
* @param loginId 指定账号
|
||||||
* @param logoutParameter 注销参数
|
* @param logoutParameter 注销参数
|
||||||
|
* @param ignoreClient 要被忽略掉的 client,填 null 代表不忽略
|
||||||
*/
|
*/
|
||||||
public void ssoLogout(Object loginId, SaLogoutParameter logoutParameter) {
|
public void ssoLogout(Object loginId, SaLogoutParameter logoutParameter, String ignoreClient) {
|
||||||
|
|
||||||
// 1、消息推送:单点注销
|
// 1、消息推送:单点注销
|
||||||
pushToAllClientByLogoutCall(loginId, logoutParameter);
|
pushToAllClientByLogoutCall(loginId, logoutParameter, ignoreClient);
|
||||||
|
|
||||||
// 2、SaSession 挂载的 Client 端注销会话
|
// 2、SaSession 挂载的 Client 端注销会话
|
||||||
SaSession session = getStpLogicOrGlobal().getSessionByLoginId(loginId, false);
|
SaSession session = getStpLogicOrGlobal().getSessionByLoginId(loginId, false);
|
||||||
@@ -717,7 +718,7 @@ public class SaSsoServerTemplate extends SaSsoTemplate {
|
|||||||
public void pushToAllClient(SaSsoMessage message, String ignoreClient) {
|
public void pushToAllClient(SaSsoMessage message, String ignoreClient) {
|
||||||
List<SaSsoClientModel> needPushClients = getNeedPushClients();
|
List<SaSsoClientModel> needPushClients = getNeedPushClients();
|
||||||
for (SaSsoClientModel client : needPushClients) {
|
for (SaSsoClientModel client : needPushClients) {
|
||||||
if(ignoreClient != null && ignoreClient.equals(client.getClient())) {
|
if(SaFoxUtil.isNotEmpty(ignoreClient) && ignoreClient.equals(client.getClient())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strategy.asyncRun.run(() -> pushMessage(client, message));
|
strategy.asyncRun.run(() -> pushMessage(client, message));
|
||||||
@@ -729,10 +730,14 @@ public class SaSsoServerTemplate extends SaSsoTemplate {
|
|||||||
*
|
*
|
||||||
* @param loginId /
|
* @param loginId /
|
||||||
* @param logoutParameter 注销参数
|
* @param logoutParameter 注销参数
|
||||||
|
* @param ignoreClient 要被忽略掉的 client,填 null 代表不忽略
|
||||||
*/
|
*/
|
||||||
public void pushToAllClientByLogoutCall(Object loginId, SaLogoutParameter logoutParameter) {
|
public void pushToAllClientByLogoutCall(Object loginId, SaLogoutParameter logoutParameter, String ignoreClient) {
|
||||||
List<SaSsoClientModel> npClients = getNeedPushClients();
|
List<SaSsoClientModel> npClients = getNeedPushClients();
|
||||||
for (SaSsoClientModel client : npClients) {
|
for (SaSsoClientModel client : npClients) {
|
||||||
|
if(SaFoxUtil.isNotEmpty(ignoreClient) && ignoreClient.equals(client.getClient())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(client.getIsSlo()) {
|
if(client.getIsSlo()) {
|
||||||
strategy.asyncRun.run(() -> {
|
strategy.asyncRun.run(() -> {
|
||||||
pushToClientByLogoutCall(client, loginId, false, logoutParameter);
|
pushToClientByLogoutCall(client, loginId, false, logoutParameter);
|
||||||
|
|||||||
@@ -238,9 +238,10 @@ public class SaSsoServerUtil {
|
|||||||
*
|
*
|
||||||
* @param loginId 指定账号
|
* @param loginId 指定账号
|
||||||
* @param logoutParameter 注销参数
|
* @param logoutParameter 注销参数
|
||||||
|
* @param ignoreClient 要被忽略掉的 client,填 null 代表不忽略
|
||||||
*/
|
*/
|
||||||
public static void ssoLogout(Object loginId, SaLogoutParameter logoutParameter) {
|
public static void ssoLogout(Object loginId, SaLogoutParameter logoutParameter, String ignoreClient) {
|
||||||
SaSsoServerProcessor.instance.ssoServerTemplate.ssoLogout(loginId, logoutParameter);
|
SaSsoServerProcessor.instance.ssoServerTemplate.ssoLogout(loginId, logoutParameter, ignoreClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user