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 52 53 54 55 56 57 58 59 60
| package com.manpower.interceptor; import com.manpower.util.JwtUtil; import io.jsonwebtoken.Claims; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class MyInterceptor implements HandlerInterceptor { @Autowired StringRedisTemplate redisTemplate; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String requestToken = request.getHeader("Authorization"); if(!StringUtils.isEmpty(requestToken)){ Claims claims = JwtUtil.checkToken(request.getHeader("Authorization")); if (claims != null) { String token = redisTemplate.opsForValue().get("operToken"+claims.get("operNo")); if(Boolean.TRUE.equals(redisTemplate.hasKey("operToken" + claims.get("operNo")))){ if(requestToken.equals(token)){ return true; }else { response.setStatus(411); return false; } }else { response.setStatus(410); return false; } } response.setStatus(409); return false; } response.setStatus(409);
return true; } @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 {
} }
|