| | |
| | | public class Intercept implements HandlerInterceptor { |
| | | |
| | | @Resource |
| | | NewsAdminService newsAdminService; |
| | | @Resource |
| | | NewsIpService newsIpService; |
| | | |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { |
| | | List<String> ips = newsIpService.list().stream().map(item->item.getIpAddess()).collect(Collectors.toList()); |
| | | if (!ips.contains(request.getRemoteAddr())){ |
| | | List<String> ips = newsIpService.list().stream().map(item -> item.getIpAddess()).collect(Collectors.toList()); |
| | | if (!ips.contains(request.getRemoteAddr())) { |
| | | return false; |
| | | |
| | | } |
| | | String token = request.getHeader("token"); |
| | | JwtTokenUtil jwtTokenUtil = new JwtTokenUtil(); |
| | | if (token==null||token.isEmpty()){ |
| | | // String token = request.getHeader("token"); |
| | | // JwtTokenUtil jwtTokenUtil = new JwtTokenUtil(); |
| | | // if (token==null||token.isEmpty()){ |
| | | // response.sendRedirect(""); |
| | | // return true; |
| | | throw new ApiException("用户未登录"); |
| | | } |
| | | AuthInfo authInfo = jwtTokenUtil.parseToken(token); |
| | | if (authInfo == null) { |
| | | throw new ApiException("未认证用户"); |
| | | } |
| | | if (newsAdminService.getOne(new LambdaQueryWrapper<NewsAdmin>().eq(NewsAdmin::getUsername, authInfo.getUsername())) == null) { |
| | | throw new ApiException("不是系统用户"); |
| | | } else { |
| | | // throw new ApiException("用户未登录"); |
| | | // } |
| | | // AuthInfo authInfo = jwtTokenUtil.parseToken(token); |
| | | // if (authInfo == null) { |
| | | // throw new ApiException("未认证用户"); |
| | | // } |
| | | // if (newsAdminService.getOne(new LambdaQueryWrapper<NewsAdmin>().eq(NewsAdmin::getUsername, authInfo.getUsername())) == null) { |
| | | // throw new ApiException("不是系统用户"); |
| | | // } else { |
| | | return true; |
| | | } |
| | | // } |
| | | |
| | | } |
| | | |