package com.szwl.aspect; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; 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.WebMvcConfigurationSupport; @Configuration public class MyWebMvcConfigurer extends WebMvcConfigurationSupport { @Value("${swagger.url:[]}") private String[] swaggerExcludes; // 白名单 @Value("${permitAll.url:[]}") private String[] permitAll; @Autowired private HeadTokenInterceptor headTokenInterceptor; @Override public void addInterceptors(InterceptorRegistry registry) { // 自定义去除的路径 String[] myExcludes = { "/tAdmin/**", "/tMessageCode/**", "/tJoinpayMch/**", "/tJoinpayMchCheck/**", "/tLogo/**", "/tProportion/**", "/tProduct/**", "/tPromoCode/**", "/tApkInfo/**", "/tTimeRule/**", "/sysRoleMenu/**", "/tEquipmentApply/**", "/tEquipment/**", "/api/**", "/tOrder/**", "/tAlarmClock/**", "/tNotice/**", "/tParameters/**", "/tLabel/**", "/tArea/**", "/error", "/tWechat/**", "/wxLogin/**", "/syncOldAdmin/**", "/syncOldAll/**", "/syncOldEquipment/**", "/syncOldProduct/**", "/syncOldProportion/**", "/syncOldJoinpayMch/**", "/tLocationCheck/**", "/tTest/**", "/tHotUpdate/**", "/tAlarmClean/**" }; registry.addInterceptor(headTokenInterceptor) .addPathPatterns("/**") // 排除swagger路径 .excludePathPatterns(swaggerExcludes) // 排除白名单路径 .excludePathPatterns(permitAll) // 排除自定义路径 .excludePathPatterns(myExcludes); // 特别包含需要进行TOKEN检查的路径 for (String path : new String[]{ "/tAdmin/getAdminList", "/tAdmin/getRelation", "/tAdmin/getAdmin", "/tJoinpayMch/getOne", "/tEquipment/findList", "/tEquipment/listEquipment", "/tEquipment/getMachineNum", "/tHuifuMch/getHuifuMchCheck" }) { registry.addInterceptor(headTokenInterceptor) .addPathPatterns(path); } // 添加Spring Security默认的拦截器 super.addInterceptors(registry); } /** * 添加静态资源 * * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } }