提交 | 用户 | 时间
|
fd2207
|
1 |
package com.jcdm.framework.security.handle; |
懒 |
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.jcdm.common.constant.Constants; |
|
13 |
import com.jcdm.common.core.domain.AjaxResult; |
|
14 |
import com.jcdm.common.core.domain.model.LoginUser; |
|
15 |
import com.jcdm.common.utils.ServletUtils; |
|
16 |
import com.jcdm.common.utils.StringUtils; |
|
17 |
import com.jcdm.framework.manager.AsyncManager; |
|
18 |
import com.jcdm.framework.manager.factory.AsyncFactory; |
|
19 |
import com.jcdm.framework.web.service.TokenService; |
|
20 |
|
|
21 |
/** |
|
22 |
* 自定义退出处理类 返回成功 |
|
23 |
* |
|
24 |
* @author jc |
|
25 |
*/ |
|
26 |
@Configuration |
|
27 |
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler |
|
28 |
{ |
|
29 |
@Autowired |
|
30 |
private TokenService tokenService; |
|
31 |
|
|
32 |
/** |
|
33 |
* 退出处理 |
|
34 |
* |
|
35 |
* @return |
|
36 |
*/ |
|
37 |
@Override |
|
38 |
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) |
|
39 |
throws IOException, ServletException |
|
40 |
{ |
|
41 |
LoginUser loginUser = tokenService.getLoginUser(request); |
|
42 |
if (StringUtils.isNotNull(loginUser)) |
|
43 |
{ |
|
44 |
String userName = loginUser.getUsername(); |
|
45 |
// 删除用户缓存记录 |
|
46 |
tokenService.delLoginUser(loginUser.getToken()); |
|
47 |
// 记录用户退出日志 |
|
48 |
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功")); |
|
49 |
} |
|
50 |
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success("退出成功"))); |
|
51 |
} |
|
52 |
} |