package cn.efunbox.audio.config; import cn.efunbox.audio.aop.*; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * 用户权限验证拦截器 * Created by yao on 17-9-29. */ @Configuration @EnableWebMvc public class Config extends WebMvcConfigurerAdapter { /** * 直接采用new interceptor或Autowired注入拦截器会导致dao为null的错误 * * @return */ @Bean AuthInterceptor authInterceptor() { return new AuthInterceptor(); } @Bean AdminInterceptor adminInterceptor() { return new AdminInterceptor(); } @Bean AllowOriginIntercepter allowOriginIntercepter() { return new AllowOriginIntercepter(); } @Bean IgnoreOptionsInterceptor ignoreOptionsInterceptor() { return new IgnoreOptionsInterceptor(); } @Bean ResLogInterceptor resLogInterceptor() { return new ResLogInterceptor(); } @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(authInterceptor()) .addPathPatterns("/audio/search", "/audio/searchList", "/audio/info/{audioId}", "/album", "/album/{albumId}") .excludePathPatterns("/device/**", "/error", "/audio/*"); registry.addInterceptor(adminInterceptor()) .addPathPatterns("/**", "/device/update", "/device/delete") .excludePathPatterns("/device/**", "/audio/info/{audioId}", "/error", "/admin/login", "/audio/search", "/file/**", "/audio/searchList", "/statistics", "/album", "/album/{albumId}") .excludePathPatterns("/getTypeList", "/getTypeContentList", "/getContentDetail", "/getContentChapterList", "/getChapterDetail", "/getTypeUpdateList", "/getContentUpdateList", "/getChapterUpdateList", "/getTypeUpdateList/**", "/getContentUpdateList/**", "/getChapterUpdateList/**") .excludePathPatterns("/api/hag/v1/**"); //杭研开放接口 //.excludePathPatterns("/getTypeList","/getTypeContentList","/getContentDetail","/getContentChapterList","/getChapterDetail","/getTypeUpdateList","/getContentUpdateList","/getChapterUpdateList"); registry.addInterceptor(ignoreOptionsInterceptor()) .addPathPatterns("/**") //杭研开放接口 .excludePathPatterns("/getTypeList", "/getTypeContentList", "/getContentDetail", "/getContentChapterList", "/getChapterDetail", "/getTypeUpdateList", "/getContentUpdateList", "/getChapterUpdateList"); registry.addInterceptor(allowOriginIntercepter()) .addPathPatterns("/**"); //杭研接口日志拦截器 registry.addInterceptor(resLogInterceptor()) .addPathPatterns("/getTypeList", "/getTypeContentList", "/getContentDetail", "/getContentChapterList", "/getChapterDetail", "/getTypeUpdateList", "/getContentUpdateList", "/getChapterUpdateList"); } // /** // * 允许跨域访问 // * @param registry // */ // @Override // public void addCorsMappings(CorsRegistry registry) { // registry.addMapping("/**") // .allowedOrigins("*") // .allowCredentials(true) // .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS") //// .allowedMethods("*") //// .allowedHeaders("*") // .maxAge(3600); // } }