| | |
| | | package com.ruoyi.common.security.interceptor; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.ruoyi.system.api.model.LoginUserParent; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.AsyncHandlerInterceptor; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.context.SecurityContextHolder; |
| | | import com.ruoyi.common.core.utils.ServletUtils; |
| | |
| | | import com.ruoyi.common.security.auth.AuthUtil; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import com.ruoyi.system.api.model.LoginUserParent; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.AsyncHandlerInterceptor; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * 自定义请求头拦截器,将Header数据封装到线程变量中方便获取 |
| | |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class HeaderInterceptor implements AsyncHandlerInterceptor |
| | | { |
| | | public class HeaderInterceptor implements AsyncHandlerInterceptor { |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception |
| | | { |
| | | if (!(handler instanceof HandlerMethod)) |
| | | { |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | if (!(handler instanceof HandlerMethod)) { |
| | | return true; |
| | | } |
| | | |
| | |
| | | SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY)); |
| | | |
| | | String token = SecurityUtils.getToken(); |
| | | if (StringUtils.isNotEmpty(token)) |
| | | { |
| | | if (StringUtils.isNotEmpty(token)) { |
| | | LoginUser loginUser = AuthUtil.getLoginUser(token); |
| | | if (StringUtils.isNotNull(loginUser)) |
| | | { |
| | | if (StringUtils.isNotNull(loginUser)) { |
| | | AuthUtil.verifyLoginUserExpire(loginUser); |
| | | SecurityContextHolder.set(SecurityConstants.LOGIN_USER, loginUser); |
| | | } |
| | | LoginUserParent loginUser1 = AuthUtil.getLoginUser1(token); |
| | | if (StringUtils.isNotNull(loginUser1)) |
| | | { |
| | | if (StringUtils.isNotNull(loginUser1)) { |
| | | AuthUtil.verifyLoginUserExpire1(loginUser1); |
| | | SecurityContextHolder.set(SecurityConstants.LOGIN_USER, loginUser); |
| | | } |
| | | // LoginUserParent loginUserStudy = AuthUtil.getLoginUserStudy(token); |
| | | // if (StringUtils.isNotNull(loginUserStudy)) { |
| | | // AuthUtil.verifyLoginUserStudyExpire(loginUserStudy); |
| | | // SecurityContextHolder.set(SecurityConstants.USER_STUDY_KEY, loginUserStudy); |
| | | // } else { |
| | | // return false; |
| | | // } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) |
| | | throws Exception |
| | | { |
| | | throws Exception { |
| | | SecurityContextHolder.remove(); |
| | | } |
| | | } |