package org.springblade.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.firewall.DefaultHttpFirewall;
import org.springframework.security.web.firewall.HttpFirewall;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfiguration implements WebMvcConfigurer {
	/**
	 * 这里需要先将拦截器注入，不然无法拦截器中的注入其他bean
	 */
	@Bean
	public SwaggerLanJInterceptor getSwaggerLanJInterceptor() {
		return new SwaggerLanJInterceptor();
	}

	@Bean
	public SwaggerLanJ2Interceptor getSwaggerLanJ2Interceptor() {
		return new SwaggerLanJ2Interceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 配置拦截路径（所有路径都拦截），也可以配置排除的路径.excludePathPatterns()
		registry.addInterceptor(getSwaggerLanJInterceptor()).addPathPatterns("/swagger-resources");
		registry.addInterceptor(getSwaggerLanJ2Interceptor()).addPathPatterns("/sys/**");
	}

	@Bean
	public HttpFirewall httpFirewall() {
		return new DefaultHttpFirewall();
	}


}
