content: package com.yuu.ymall.web.admin.web.interceptor;
  
  import org.apache.shiro.SecurityUtils;
  import org.apache.shiro.subject.Subject;
  import org.springframework.web.servlet.HandlerInterceptor;
  import org.springframework.web.servlet.ModelAndView;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * 权限拦截器
   *
   * @Classname PermissionInterceptor
   * @Date 2019/5/12 22:31
   * @Created by Yuu
   */
  public class PermissionInterceptor implements HandlerInterceptor {
      @Override
      public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
          return true;
      }
  
      @Override
      public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
          // 以 login 结尾的请求
          if (modelAndView != null && modelAndView.getViewName() != null && modelAndView.getViewName().endsWith("login")) {
              Subject subject = SecurityUtils.getSubject();
              if (subject.isAuthenticated()) {
                  httpServletResponse.sendRedirect("/");
              }
          }
      }
  
      @Override
      public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
  
      }
  }
  