!7 修复退出功能 退出后重定向到登录页

Merge pull request !7 from dxyx/master
This commit is contained in:
芋道源码 2021-03-08 22:53:52 +08:00 committed by Gitee
commit ad54e58acd
3 changed files with 22 additions and 3 deletions

View File

@ -152,7 +152,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.headers().frameOptions().disable(); .headers().frameOptions().disable();
httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); httpSecurity.logout().logoutUrl(webProperties.getApiPrefix() + "/logout").logoutSuccessHandler(logoutSuccessHandler);
// 添加 JWT Filter // 添加 JWT Filter
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.dashboard.framework.security.core.handler; package cn.iocoder.dashboard.framework.security.core.handler;
import cn.hutool.core.util.StrUtil; 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.config.SecurityProperties;
import cn.iocoder.dashboard.framework.security.core.service.SecurityAuthFrameworkService; import cn.iocoder.dashboard.framework.security.core.service.SecurityAuthFrameworkService;
import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils;
@ -36,6 +37,6 @@ public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
securityFrameworkService.logout(token); securityFrameworkService.logout(token);
} }
// 返回成功 // 返回成功
ServletUtils.writeJSON(response, null); ServletUtils.writeJSON(response, CommonResult.success(null));
} }
} }

View File

@ -160,7 +160,25 @@ public class SysAuthServiceImpl implements SysAuthService {
@Override @Override
public void logout(String token) { 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 @Override