| | |
| | | package com.ycl.jxkg.config.spring.security; |
| | | |
| | | import com.ycl.jxkg.base.SystemCode; |
| | | import com.ycl.jxkg.constants.CaffeineConstant; |
| | | import com.ycl.jxkg.domain.entity.UserEventLog; |
| | | import com.ycl.jxkg.enums.general.YesOrNoEnum; |
| | | import com.ycl.jxkg.event.UserEvent; |
| | | import com.ycl.jxkg.service.UserService; |
| | | import com.ycl.jxkg.utils.CaffeineUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | |
| | | import org.springframework.security.core.userdetails.User; |
| | | import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | |
| | | private final ApplicationEventPublisher eventPublisher; |
| | | private final UserService userService; |
| | | private final CaffeineUtil caffeineUtil; |
| | | |
| | | /** |
| | | * Instantiates a new Rest authentication success handler. |
| | |
| | | * @param userService the user service |
| | | */ |
| | | @Autowired |
| | | public RestAuthenticationSuccessHandler(ApplicationEventPublisher eventPublisher, UserService userService) { |
| | | public RestAuthenticationSuccessHandler(ApplicationEventPublisher eventPublisher, UserService userService, CaffeineUtil caffeineUtil) { |
| | | this.eventPublisher = eventPublisher; |
| | | this.userService = userService; |
| | | this.caffeineUtil = caffeineUtil; |
| | | } |
| | | |
| | | @Override |
| | |
| | | Object object = authentication.getPrincipal(); |
| | | if (null != object) { |
| | | User springUser = (User) object; |
| | | // 登录之后保存或更新 用户名与session的关系 |
| | | String sessionId = request.getSession().getId(); |
| | | caffeineUtil.put(CaffeineConstant.AUTH, springUser.getUsername(), sessionId); |
| | | com.ycl.jxkg.domain.entity.User user = userService.getUserByUserName(springUser.getUsername()); |
| | | if (null != user) { |
| | | // 密码过期返回强制修改密码标识 |