| | |
| | | package com.ycl.jxkg.config.spring.security; |
| | | |
| | | import com.ycl.jxkg.base.SystemCode; |
| | | import com.ycl.jxkg.domain.User; |
| | | import com.ycl.jxkg.domain.UserEventLog; |
| | | import com.ycl.jxkg.constants.CaffeineConstant; |
| | | import com.ycl.jxkg.domain.entity.User; |
| | | import com.ycl.jxkg.domain.entity.UserEventLog; |
| | | import com.ycl.jxkg.event.UserEvent; |
| | | import com.ycl.jxkg.service.UserService; |
| | | import com.ycl.jxkg.utils.CaffeineUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | |
| | | private final ApplicationEventPublisher eventPublisher; |
| | | private final UserService userService; |
| | | private final CaffeineUtil caffeineUtil; |
| | | |
| | | /** |
| | | * Instantiates a new Rest logout success handler. |
| | |
| | | * @param userService the user service |
| | | */ |
| | | @Autowired |
| | | public RestLogoutSuccessHandler(ApplicationEventPublisher eventPublisher, UserService userService) { |
| | | public RestLogoutSuccessHandler(ApplicationEventPublisher eventPublisher, UserService userService, CaffeineUtil caffeineUtil) { |
| | | this.eventPublisher = eventPublisher; |
| | | this.userService = userService; |
| | | this.caffeineUtil = caffeineUtil; |
| | | } |
| | | |
| | | @Override |
| | | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { |
| | | org.springframework.security.core.userdetails.User springUser = (org.springframework.security.core.userdetails.User) authentication.getPrincipal(); |
| | | if (null != springUser) { |
| | | // 清除用户名和sessionId之间的绑定 |
| | | caffeineUtil.remove(CaffeineConstant.AUTH, springUser.getUsername()); |
| | | SecurityContextHolder.clearContext(); |
| | | User user = userService.getUserByUserName(springUser.getUsername()); |
| | | UserEventLog userEventLog = new UserEventLog(user.getId(), user.getUserName(), user.getRealName(), new Date()); |
| | | userEventLog.setContent(user.getUserName() + " 登出了学之思开源考试系统"); |