中国算力平台算力登记系统2.0
YZFG
2024-09-30 43dc2996fd2033991539ed35a0429238829a5417
commit | author | age
43dc29 1 package com.odcc.cpzidc.framework.security.handle;
Y 2
3 import java.io.IOException;
4 import javax.servlet.ServletException;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.context.annotation.Configuration;
9 import org.springframework.security.core.Authentication;
10 import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
11 import com.alibaba.fastjson2.JSON;
12 import com.odcc.cpzidc.common.constant.Constants;
13 import com.odcc.cpzidc.common.core.domain.AjaxResult;
14 import com.odcc.cpzidc.common.core.domain.model.LoginUser;
15 import com.odcc.cpzidc.common.utils.MessageUtils;
16 import com.odcc.cpzidc.common.utils.ServletUtils;
17 import com.odcc.cpzidc.common.utils.StringUtils;
18 import com.odcc.cpzidc.framework.manager.AsyncManager;
19 import com.odcc.cpzidc.framework.manager.factory.AsyncFactory;
20 import com.odcc.cpzidc.framework.web.service.TokenService;
21
22 /**
23  * 自定义退出处理类 返回成功
24  * 
25  * @author ruoyi
26  */
27 @Configuration
28 public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler
29 {
30     @Autowired
31     private TokenService tokenService;
32
33     /**
34      * 退出处理
35      * 
36      * @return
37      */
38     @Override
39     public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
40             throws IOException, ServletException
41     {
42         LoginUser loginUser = tokenService.getLoginUser(request);
43         if (StringUtils.isNotNull(loginUser))
44         {
45             String userName = loginUser.getUsername();
46             // 删除用户缓存记录
47             tokenService.delLoginUser(loginUser.getToken());
48             // 记录用户退出日志
49             AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
50         }
51         ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success(MessageUtils.message("user.logout.success"))));
52     }
53 }