| | |
| | | package com.yuanchu.mom.config; |
| | | |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | | import com.yuanchu.mom.utils.Jwt; |
| | | import com.yuanchu.mom.utils.RedisUtil; |
| | |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | |
| | | @Value("${server.port}") |
| | | private String serverPort; |
| | | |
| | | private static ThreadLocal<String> threadLocal = new ThreadLocal<>(); |
| | | |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) { |
| | | response.setStatus(HttpServletResponse.SC_OK); |
| | | return true; |
| | | } |
| | | try { |
| | | HandlerMethod h = (HandlerMethod)handler; |
| | | ValueAuth annotation = h.getMethodAnnotation(ValueAuth.class); |
| | | if(annotation!=null){ |
| | | return true; |
| | | } |
| | | }catch (Exception e){ |
| | | return true; |
| | | } |
| | | String[] strs = request.getRequestURL().toString().split(serverPort); |
| | | AtomicBoolean judge = new AtomicBoolean(false); |
| | | list.forEach(a -> { |
| | | if (strs[1].equals(a)) { |
| | | for (String s : list) { |
| | | if (strs[1].equals(s)) { |
| | | judge.set(true); |
| | | return; |
| | | } else if (a.indexOf("/**") > -1) { |
| | | if (strs[1].indexOf(a.replace("/**", "")) == 0) { |
| | | break; |
| | | } else if (s.indexOf("/**") > -1) { |
| | | if (strs[1].indexOf(s.replace("/**", "")) == 0) { |
| | | judge.set(true); |
| | | return; |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | if (judge.get()) return true; |
| | | response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
| | | response.setCharacterEncoding("UTF-8"); |
| | |
| | | |
| | | @Override |
| | | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
| | | // System.out.println("-------------------------拦截器校验通过---------------------------"); |
| | | |
| | | } |
| | | |
| | | private List<String> list; |
| | |
| | | |
| | | list.add("/user/enter"); |
| | | list.add("/user/refresh"); |
| | | list.add("/outPath/**"); |
| | | this.list = list; |
| | | } |
| | | |