Commit ad54e58acda66c6860f270bb158333da9a26c424
Committed by
Gitee
!7 修复退出功能 退出后重定向到登录页
Merge pull request !7 from dxyx/master
Showing
3 changed files
with
22 additions
and
3 deletions
src/main/java/cn/iocoder/dashboard/framework/security/config/SecurityConfiguration.java
| ... | ... | @@ -152,7 +152,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { |
| 152 | 152 | .anyRequest().authenticated() |
| 153 | 153 | .and() |
| 154 | 154 | .headers().frameOptions().disable(); |
| 155 | - httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); | |
| 155 | + httpSecurity.logout().logoutUrl(webProperties.getApiPrefix() + "/logout").logoutSuccessHandler(logoutSuccessHandler); | |
| 156 | 156 | // 添加 JWT Filter |
| 157 | 157 | httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); |
| 158 | 158 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/security/core/handler/LogoutSuccessHandlerImpl.java
| 1 | 1 | package cn.iocoder.dashboard.framework.security.core.handler; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | +import cn.iocoder.dashboard.common.pojo.CommonResult; | |
| 4 | 5 | import cn.iocoder.dashboard.framework.security.config.SecurityProperties; |
| 5 | 6 | import cn.iocoder.dashboard.framework.security.core.service.SecurityAuthFrameworkService; |
| 6 | 7 | import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils; |
| ... | ... | @@ -36,6 +37,6 @@ public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { |
| 36 | 37 | securityFrameworkService.logout(token); |
| 37 | 38 | } |
| 38 | 39 | // 返回成功 |
| 39 | - ServletUtils.writeJSON(response, null); | |
| 40 | + ServletUtils.writeJSON(response, CommonResult.success(null)); | |
| 40 | 41 | } |
| 41 | 42 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/auth/impl/SysAuthServiceImpl.java
| ... | ... | @@ -160,7 +160,25 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 160 | 160 | |
| 161 | 161 | @Override |
| 162 | 162 | public void logout(String token) { |
| 163 | -// AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功")); TODO 需要搞一搞 | |
| 163 | + // 查询用户信息 | |
| 164 | + LoginUser loginUser = userSessionService.getLoginUser(token); | |
| 165 | + if(loginUser == null) { | |
| 166 | + return; | |
| 167 | + } | |
| 168 | + // 删除session | |
| 169 | + userSessionService.deleteUserSession(token); | |
| 170 | + this.createLogoutLog(loginUser.getUsername(), SysLoginResultEnum.SUCCESS); | |
| 171 | + } | |
| 172 | + | |
| 173 | + private void createLogoutLog(String username, SysLoginResultEnum loginResult) { | |
| 174 | + SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); | |
| 175 | + reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); | |
| 176 | + reqVO.setTraceId(TracerUtils.getTraceId()); | |
| 177 | + reqVO.setUsername(username); | |
| 178 | + reqVO.setUserAgent(ServletUtils.getUserAgent()); | |
| 179 | + reqVO.setUserIp(ServletUtils.getClientIP()); | |
| 180 | + reqVO.setResult(loginResult.getResult()); | |
| 181 | + loginLogService.createLoginLog(reqVO); | |
| 164 | 182 | } |
| 165 | 183 | |
| 166 | 184 | @Override | ... | ... |