package cn.com.poc.common.interceptor;


import cn.com.yict.framemax.core.spring.mvc.MvcHandlerInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class AuthenticationInterceptor implements MvcHandlerInterceptor {

    private final Logger logger = LoggerFactory.getLogger(AuthenticationInterceptor.class);

//    @Resource
//    private BizProjectService bizProjectService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        logger.info("request请求地址path[{}] uri[{}]", request.getServletPath(), request.getRequestURI());
//        直接放行获取Token
//        String token = request.getHeader("x-request-token");
//        if (StringUtils.isBlank(token)) {
//            return true;
//        }
//        if (RunEnv.dev.equals(Config.getRunEnv())) {
//            return true;
//        }
//
//        String headerTimestamp = request.getHeader("timestamp");
//        String headerSign = request.getHeader("x-request-sign");
//        if (StringUtils.isBlank(headerSign) && StringUtils.isBlank(headerTimestamp)) {
//            throw new I18nMessageException("Missing parameters in request header");
//        }
//
//        //计算签名
//        UserBaseEntity currentUser = BlContext.getCurrentUser();
//        String appKey = currentUser.getUserAccount();
//        BizProjectEntity bizProjectEntity = bizProjectService.getSecretByAppKey(appKey);
//        SignUtil.signVerification(headerSign, bizProjectEntity.getAppSecret(), headerTimestamp, request.getRequestURI());
        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 {
    }
}
