1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package cn.efunbox.audio.config;
- import cn.efunbox.audio.aop.AdminInterceptor;
- import cn.efunbox.audio.aop.AllowOriginIntercepter;
- import cn.efunbox.audio.aop.AuthInterceptor;
- import cn.efunbox.audio.aop.IgnoreOptionsInterceptor;
- 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();
- }
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(authInterceptor())
- .addPathPatterns("/audio/search")
- .excludePathPatterns("/device/**", "/error");
- registry.addInterceptor(adminInterceptor())
- .addPathPatterns("/**", "/device/update", "/device/delete")
- .excludePathPatterns("/device/**", "/error", "/admin/login", "/audio/search","/file/**");
- registry.addInterceptor(ignoreOptionsInterceptor())
- .addPathPatterns("/**");
- // registry.addInterceptor(allowOriginIntercepter())
- // .addPathPatterns("/**");
- }
- // /**
- // * 允许跨域访问
- // * @param registry
- // */
- // @Override
- // public void addCorsMappings(CorsRegistry registry) {
- // registry.addMapping("/**")
- // .allowedOrigins("*")
- // .allowCredentials(true)
- // .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
- //// .allowedMethods("*")
- //// .allowedHeaders("*")
- // .maxAge(3600);
- // }
- }
|