From eca27cd18faef135a9b226334a2b265b074b3353 Mon Sep 17 00:00:00 2001 From: asas6559 <302811456@qq.com> Date: Mon, 8 Mar 2021 20:41:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=80=E5=87=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=20=E9=80=80=E5=87=BA=E5=90=8E=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91=E5=88=B0=E7=99=BB=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/security/config/SecurityConfiguration.java | 2 +- .../security/core/handler/LogoutSuccessHandlerImpl.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/iocoder/dashboard/framework/security/config/SecurityConfiguration.java b/src/main/java/cn/iocoder/dashboard/framework/security/config/SecurityConfiguration.java index 927c72996..2b9e2202b 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/security/config/SecurityConfiguration.java +++ b/src/main/java/cn/iocoder/dashboard/framework/security/config/SecurityConfiguration.java @@ -152,7 +152,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .anyRequest().authenticated() .and() .headers().frameOptions().disable(); - httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); + httpSecurity.logout().logoutUrl(webProperties.getApiPrefix() + "/logout").logoutSuccessHandler(logoutSuccessHandler); // 添加 JWT Filter httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); } diff --git a/src/main/java/cn/iocoder/dashboard/framework/security/core/handler/LogoutSuccessHandlerImpl.java b/src/main/java/cn/iocoder/dashboard/framework/security/core/handler/LogoutSuccessHandlerImpl.java index 07826b9ab..262f56fe2 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/security/core/handler/LogoutSuccessHandlerImpl.java +++ b/src/main/java/cn/iocoder/dashboard/framework/security/core/handler/LogoutSuccessHandlerImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.dashboard.framework.security.core.handler; import cn.hutool.core.util.StrUtil; +import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.framework.security.config.SecurityProperties; import cn.iocoder.dashboard.framework.security.core.service.SecurityAuthFrameworkService; import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils; @@ -36,6 +37,6 @@ public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { securityFrameworkService.logout(token); } // 返回成功 - ServletUtils.writeJSON(response, null); + ServletUtils.writeJSON(response, CommonResult.success(null)); } } From d5ac6e7a199e3e36b46d89445fe1f8fe3a16130a Mon Sep 17 00:00:00 2001 From: asas6559 <302811456@qq.com> Date: Mon, 8 Mar 2021 22:26:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=99=BB=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E8=AE=B0=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/auth/impl/SysAuthServiceImpl.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java index 1cbc7bb0b..d8deefaae 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java @@ -160,7 +160,23 @@ public class SysAuthServiceImpl implements SysAuthService { @Override public void logout(String token) { -// AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功")); TODO 需要搞一搞 + // 查询用户信息 + LoginUser loginUser = userSessionService.getLoginUser(token); + if(loginUser == null) return; + // 删除session + userSessionService.deleteUserSession(token); + this.createLogoutLog(loginUser.getUsername(), SysLoginResultEnum.SUCCESS); + } + + private void createLogoutLog(String username, SysLoginResultEnum loginResult) { + SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); + reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); + reqVO.setTraceId(TracerUtils.getTraceId()); + reqVO.setUsername(username); + reqVO.setUserAgent(ServletUtils.getUserAgent()); + reqVO.setUserIp(ServletUtils.getClientIP()); + reqVO.setResult(loginResult.getResult()); + loginLogService.createLoginLog(reqVO); } @Override From 4294ed2548dcffe7233cf9858bf6c51e241e238d Mon Sep 17 00:00:00 2001 From: asas6559 <302811456@qq.com> Date: Mon, 8 Mar 2021 22:34:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=99=BB=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E8=AE=B0=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/system/service/auth/impl/SysAuthServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java index d8deefaae..675d26a54 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java @@ -162,7 +162,9 @@ public class SysAuthServiceImpl implements SysAuthService { public void logout(String token) { // 查询用户信息 LoginUser loginUser = userSessionService.getLoginUser(token); - if(loginUser == null) return; + if(loginUser == null) { + return; + } // 删除session userSessionService.deleteUserSession(token); this.createLogoutLog(loginUser.getUsername(), SysLoginResultEnum.SUCCESS);