| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.authentication.event.LogoutSuccessEvent; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| | | import com.alibaba.fastjson2.JSON; |
| | |
| | | { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private ApplicationEventPublisher publisher; |
| | | /** |
| | | * 退出处理 |
| | | * |
| | |
| | | tokenService.delLoginUser(loginUser.getToken(), loginUser.getUser().getUserId()); |
| | | // 记录用户退出日志 |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); |
| | | // ✅ 手动发布注销事件 |
| | | // 构造一个 Authentication |
| | | Authentication auth = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); |
| | | publisher.publishEvent(new LogoutSuccessEvent(auth)); |
| | | } |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success(MessageUtils.message("user.logout.success")))); |
| | | } |