From a7be490dda96be26a390d7a18b5d3d1839e0e0f0 Mon Sep 17 00:00:00 2001 From: zhuxinru Date: Tue, 14 Apr 2026 16:55:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/HoneycomCustomerController.java | 2 +- .../service/HoneycomCustomerService.java | 15 ++++++++++++++- .../HoneycomLogoutSuccessEventHandler.java | 11 +++++++++-- .../log/api/feign/RemoteSpdmLogService.java | 18 ++++++++++++++++++ .../log/service/impl/SysLogServiceImpl.java | 11 +++++++++++ .../honeycom/spdm/service/SpdmService.java | 2 +- 6 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 honeycom-log/honeycom-log-api/src/main/java/com/honeycombis/honeycom/log/api/feign/RemoteSpdmLogService.java diff --git a/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/basic/HoneycomCustomerController.java b/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/basic/HoneycomCustomerController.java index fe66539..cbb4e51 100644 --- a/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/basic/HoneycomCustomerController.java +++ b/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/basic/HoneycomCustomerController.java @@ -94,7 +94,7 @@ public class HoneycomCustomerController { */ @Inner(value = false) @PostMapping("/v1/logout") - @SysLog("退出登录") +// @SysLog("退出登录") public R logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) { if (StrUtil.isBlank(authHeader)) { return R.ok(); diff --git a/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/service/HoneycomCustomerService.java b/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/service/HoneycomCustomerService.java index cf756d0..1e80c85 100644 --- a/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/service/HoneycomCustomerService.java +++ b/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/endpoint/service/HoneycomCustomerService.java @@ -5,10 +5,12 @@ import cn.hutool.core.util.StrUtil; import com.honeycombis.honeycom.common.core.constant.CacheConstants; import com.honeycombis.honeycom.common.core.util.SpringContextHolder; import com.honeycombis.honeycom.common.security.dto.ObtainTokenDTO; +import com.honeycombis.honeycom.common.security.service.HoneycomUser; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.CacheManager; import org.springframework.security.authentication.event.LogoutSuccessEvent; +import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.core.OAuth2AccessToken; import org.springframework.security.oauth2.core.OAuth2RefreshToken; import org.springframework.security.oauth2.server.authorization.OAuth2Authorization; @@ -17,6 +19,10 @@ import org.springframework.security.oauth2.server.authorization.OAuth2TokenType; import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import org.springframework.stereotype.Service; +import java.security.Principal; +import java.util.Map; +import java.util.Objects; + /** * @author sunan */ @@ -77,8 +83,15 @@ public class HoneycomCustomerService { // 清空access token authorizationService.remove(authorization); // 处理自定义退出事件,保存相关日志 + Map attributes = authorization.getAttributes(); + Authentication authentication = (Authentication) attributes.get(Principal.class.getName()); + if (Objects.isNull(authentication)) { + return; + } + HoneycomUser honeycomUser = (HoneycomUser) authentication.getPrincipal(); + SpringContextHolder.publishEvent(new LogoutSuccessEvent(new PreAuthenticatedAuthenticationToken( - authorization.getPrincipalName(), authorization.getRegisteredClientId()))); + honeycomUser.getId(), authorization.getRegisteredClientId()))); } diff --git a/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/support/handler/HoneycomLogoutSuccessEventHandler.java b/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/support/handler/HoneycomLogoutSuccessEventHandler.java index 64e2c80..ea13474 100644 --- a/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/support/handler/HoneycomLogoutSuccessEventHandler.java +++ b/honeycom-auth/src/main/java/com/honeycombis/honeycom/auth/support/handler/HoneycomLogoutSuccessEventHandler.java @@ -17,8 +17,11 @@ package com.honeycombis.honeycom.auth.support.handler; import com.honeycombis.honeycom.admin.api.dto.SysLogDTO; +import com.honeycombis.honeycom.common.core.constant.SecurityConstants; import com.honeycombis.honeycom.common.core.util.WebUtils; import com.honeycombis.honeycom.common.log.util.SysLogUtils; +import com.honeycombis.honeycom.log.api.feign.RemoteHoneyLogService; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationListener; import org.springframework.http.HttpHeaders; @@ -37,6 +40,9 @@ import org.springframework.stereotype.Component; @Component public class HoneycomLogoutSuccessEventHandler implements ApplicationListener { + @Resource + private RemoteHoneyLogService remoteLogService; + @Override public void onApplicationEvent(LogoutSuccessEvent event) { Authentication authentication = (Authentication) event.getSource(); @@ -54,7 +60,7 @@ public class HoneycomLogoutSuccessEventHandler implements ApplicationListener implements SysLogService { + private final RemoteSpdmLogService remoteSpdmLogService; + /** * 批量插入前端错误日志 * @param preLogVoList 日志信息 @@ -86,6 +91,12 @@ public class SysLogServiceImpl extends ServiceImpl impleme BeanUtils.copyProperties(sysLog, log, "createTime"); return baseMapper.insert(log); }); + + // 退出登录记录到spdm日志中去 + if ("退出登录".equals(sysLog.getTitle())) { + remoteSpdmLogService.saveLog(sysLog); + } + return Boolean.TRUE; } diff --git a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/service/SpdmService.java b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/service/SpdmService.java index b02aedf..37de18f 100644 --- a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/service/SpdmService.java +++ b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/service/SpdmService.java @@ -19,7 +19,7 @@ public class SpdmService { public void asyncSaveLog(SysLogDto sysLogDto) { try { SysLogDto sysLog = new SysLogDto(); - sysLog.setTitle("登录成功"); + sysLog.setTitle(sysLogDto.getTitle()); sysLog.setServiceId("simulation-system"); sysLog.setTenantId(sysLogDto.getTenantId()); sysLog.setCreateBy(sysLogDto.getCreateBy());