//package com.sunxung.factoring.component.interceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//
//import com.sunxung.factoring.component.annotation.Authority;
//import com.sunxung.factoring.component.util.SpringUtil;
//import com.sunxung.factoring.component.util.ThreadLocalUtil;
//import com.sunxung.factoring.service.sys.AuthorityService;
//
///**
// * 是否有操作权限拦截
// */
//public class PermissionInterceptor extends HandlerInterceptorAdapter {
//
//    private static AuthorityService authorityService;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
//            throws Exception {
//        HandlerMethod method = (HandlerMethod) handler;
//        Authority permission = method.getMethodAnnotation(Authority.class);
//        if (permission != null) {
//            if (!getAuthorityService().hasPermission(permission.value())) {
//                // 重定向显示无权信息
//               // response.sendRedirect("/authority/noPermission");
//                return false;
//            }
//        }
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
//            ModelAndView modelAndView) throws Exception {
//        if (modelAndView != null) {
//            modelAndView.addObject("globalUser", ThreadLocalUtil.getUser());
//        }
//    }
//
//    private AuthorityService getAuthorityService() {
//        if (authorityService == null) {
//            authorityService = SpringUtil.getBeanByType(AuthorityService.class);
//        }
//        return authorityService;
//    }
//}
