|  |  |  | 
|---|
|  |  |  | package com.ruoyi.framework.security.handle; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.util.Locale; | 
|---|
|  |  |  | import javax.servlet.ServletException; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.ruoyi.common.utils.MessageUtils; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.context.annotation.Configuration; | 
|---|
|  |  |  | import org.springframework.context.i18n.LocaleContextHolder; | 
|---|
|  |  |  | import org.springframework.security.core.Authentication; | 
|---|
|  |  |  | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSON; | 
|---|
|  |  |  | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author ruoyi | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Configuration | 
|---|
|  |  |  | public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | String userName = loginUser.getUsername(); | 
|---|
|  |  |  | // 删除用户缓存记录 | 
|---|
|  |  |  | tokenService.delLoginUser(loginUser.getToken()); | 
|---|
|  |  |  | // tokenService.delLoginUser(loginUser.getToken()); | 
|---|
|  |  |  | // 删除用户缓存记录 | 
|---|
|  |  |  | tokenService.delLoginUser(loginUser.getToken(), loginUser.getUser().getUserId()); | 
|---|
|  |  |  | // 记录用户退出日志 | 
|---|
|  |  |  | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功")); | 
|---|
|  |  |  | //国际化 | 
|---|
|  |  |  | final String key = "language"; | 
|---|
|  |  |  | String language = request.getHeader(key); | 
|---|
|  |  |  | if (language == null) { | 
|---|
|  |  |  | //String language = "en-US"; | 
|---|
|  |  |  | language = "en-US"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("当前语言={}", language); | 
|---|
|  |  |  | Locale locale = new Locale(language.split("-")[0], language.split("-")[1]); | 
|---|
|  |  |  | LocaleContextHolder.setLocale(locale); | 
|---|
|  |  |  | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT,MessageUtils.message("user.logout.success"))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success("退出成功"))); | 
|---|
|  |  |  | } | 
|---|