package com.leanwo.activiti.config;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class WebConfigurer implements WebMvcConfigurer {

	private static Logger logger = LoggerFactory.getLogger(WebConfigurer.class);

	@Inject
	private TokenInterceptor tokenInterceptor;
	
//	@Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/workflow-app/").setViewName("forward:/workflow-app/index.html");
//        registry.addViewController("/workflow-app/editor/").setViewName("forward:/workflow-app/editor/index.html");
//        registry.addViewController("/workflow-app/idm/").setViewName("forward:/workflow-app/idm/index.html");
//        registry.addViewController("/workflow-app/workflow/").setViewName("forward:/workflow-app/workflow/index.html");
//        registry.addViewController("/workflow-app/admin/").setViewName("forward:/workflow-app/admin/index.html");
//	}
	
//	@Override
//	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 添加虚拟目录
		// registry.addResourceHandler("/workflow-app/**").addResourceLocations("classpath:/webapp-app/");
//	}

	@Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(authenticationInterceptor())
//                .addPathPatterns("/workflow-prodog/**");    // 拦截所有请求，通过判断是否有 @LoginRequired 注解 决定是否需要登录
        registry.addInterceptor(tokenInterceptor)
        	.addPathPatterns("/workflow-prodog/**/**")
	        .addPathPatterns("/workflow-system/DatabaseResource/**")
	        .addPathPatterns("/workflow-system/AccountManagementResource/**");
    }
	
	/**
	 * 跨域支持
	 */
//	@Override
//	public void addCorsMappings(CorsRegistry registry) {
//		registry.addMapping("/**").allowedOrigins("*").allowCredentials(true)
//				.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH").maxAge(3600 * 24);
//	}
	

}