Config.java 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package cn.efunbox.audio.config;
  2. import cn.efunbox.audio.aop.*;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  6. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  7. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  8. /**
  9. * 用户权限验证拦截器
  10. * Created by yao on 17-9-29.
  11. */
  12. @Configuration
  13. @EnableWebMvc
  14. public class Config extends WebMvcConfigurerAdapter {
  15. /**
  16. * 直接采用new interceptor或Autowired注入拦截器会导致dao为null的错误
  17. *
  18. * @return
  19. */
  20. @Bean
  21. AuthInterceptor authInterceptor() {
  22. return new AuthInterceptor();
  23. }
  24. @Bean
  25. AdminInterceptor adminInterceptor() {
  26. return new AdminInterceptor();
  27. }
  28. @Bean
  29. AllowOriginIntercepter allowOriginIntercepter() {
  30. return new AllowOriginIntercepter();
  31. }
  32. @Bean
  33. IgnoreOptionsInterceptor ignoreOptionsInterceptor() {
  34. return new IgnoreOptionsInterceptor();
  35. }
  36. @Bean
  37. ResLogInterceptor resLogInterceptor() {
  38. return new ResLogInterceptor();
  39. }
  40. @Override
  41. public void addInterceptors(InterceptorRegistry registry) {
  42. registry.addInterceptor(authInterceptor())
  43. .addPathPatterns("/audio/search", "/audio/searchList", "/audio/info/{audioId}", "/album", "/album/{albumId}")
  44. .excludePathPatterns("/device/**", "/error", "/audio/*");
  45. registry.addInterceptor(adminInterceptor())
  46. .addPathPatterns("/**", "/device/update", "/device/delete")
  47. .excludePathPatterns("/device/**", "/audio/info/{audioId}", "/error", "/admin/login", "/audio/search", "/file/**", "/audio/searchList", "/statistics", "/album", "/album/{albumId}")
  48. .excludePathPatterns("/getTypeList", "/getTypeContentList", "/getContentDetail", "/getContentChapterList", "/getChapterDetail", "/getTypeUpdateList", "/getContentUpdateList", "/getChapterUpdateList", "/getTypeUpdateList/**", "/getContentUpdateList/**", "/getChapterUpdateList/**")
  49. .excludePathPatterns("/api/hag/v1/**");
  50. //杭研开放接口
  51. //.excludePathPatterns("/getTypeList","/getTypeContentList","/getContentDetail","/getContentChapterList","/getChapterDetail","/getTypeUpdateList","/getContentUpdateList","/getChapterUpdateList");
  52. registry.addInterceptor(ignoreOptionsInterceptor())
  53. .addPathPatterns("/**")
  54. //杭研开放接口
  55. .excludePathPatterns("/getTypeList", "/getTypeContentList", "/getContentDetail", "/getContentChapterList", "/getChapterDetail", "/getTypeUpdateList", "/getContentUpdateList", "/getChapterUpdateList");
  56. registry.addInterceptor(allowOriginIntercepter())
  57. .addPathPatterns("/**");
  58. //杭研接口日志拦截器
  59. registry.addInterceptor(resLogInterceptor())
  60. .addPathPatterns("/getTypeList", "/getTypeContentList", "/getContentDetail", "/getContentChapterList", "/getChapterDetail", "/getTypeUpdateList", "/getContentUpdateList", "/getChapterUpdateList");
  61. }
  62. // /**
  63. // * 允许跨域访问
  64. // * @param registry
  65. // */
  66. // @Override
  67. // public void addCorsMappings(CorsRegistry registry) {
  68. // registry.addMapping("/**")
  69. // .allowedOrigins("*")
  70. // .allowCredentials(true)
  71. // .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
  72. //// .allowedMethods("*")
  73. //// .allowedHeaders("*")
  74. // .maxAge(3600);
  75. // }
  76. }