jiazx0107@163.com
2023-11-04 43ce77a85d8297a53dc25430fff10ead57296167
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.ld.igds.adepter;
 
import com.bstek.bdf2.core.business.IUser;
import com.ld.igds.exception.TimeoutException;
import com.ld.igds.util.ContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
/**
 * @author andy.jia
 * @desc 拦截器,用于拦截三维模型和APP请求中是否包含会话信息,在WebMvcConfig中配置其拦截的路径
 * @date 2019/4/26 0026
 **/
@Slf4j
public class MyRequestHandlerAdepter implements HandlerInterceptor {
 
    @Override
    public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {
    }
 
    @Override
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
            throws Exception {
    }
 
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
 
       String url =  request.getRequestURI();
       log.debug("请求路径:{}",url);
 
       //验证Session
        HttpSession session = request.getSession();
        if (null == session) {
            throw new TimeoutException();
        }
 
        //验证Session中的用户
        IUser user = ContextUtil.getLoginUser();
        if (null == user) {
            throw new TimeoutException();
        }
        return true;
    }
}