package com.xxl.job.admin.controller.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

/**
 * web mvc config
 *
 * @author xuxueli 2018-04-02 20:48:20
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private CookieInterceptor cookieInterceptor;
    
    @Resource
    private PermissionInterceptor permissionInterceptor;
    
    public static final List<String> excludePaths = new ArrayList<String>();
    
    static {
    	excludePaths.add("/admin/customJobInfo/**");
    	excludePaths.add("/v2/api-docs");
    	excludePaths.add("/swagger/**");
    	excludePaths.add("/swagger-resources/**");
    	excludePaths.add("/configuration/ui");
    	excludePaths.add("/configuration/security");
    	excludePaths.add("/swagger-ui.html");
    	excludePaths.add("/resources/**");
    	excludePaths.add("/favicon.ico");
    	//excludePaths.add("/error");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**").excludePathPatterns(excludePaths);
        registry.addInterceptor(cookieInterceptor).addPathPatterns("/**").excludePathPatterns(excludePaths);
    }
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    	registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
    	registry.addResourceHandler("/img/**").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}