123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package com.travel.config;
- import com.travel.util.JWTIntercept;
- import com.travel.util.SessionInterceptor;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.servlet.config.annotation.CorsRegistry;
- import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
- /**
- * 拦截器跟跨域解决 token拦截器
- */
- @Configuration
- public class InterceptConfig implements WebMvcConfigurer {
- @Autowired
- private SessionInterceptor sessionInterceptor;
- /**
- * 重写父类提供的跨域请求处理的接口
- *
- * @param registry
- */
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- // 添加映射路径
- // registry.addMapping("/**")
- // // 放行哪些原始域
- // .allowedOriginPatterns("*")
- // .maxAge(3600)
- // // 是否发送Cookie信息
- // .allowCredentials(true)
- // // 放行哪些原始域(请求方式)
- // .allowedMethods("*")
- // // 放行哪些原始域(头部信息)
- // .allowedHeaders("*")
- // // 暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息)
- // .exposedHeaders("Server", "Content-Length", "Authorization", "Access-Token", "Access-Control-Allow-Origin", "Access-Control-Allow-Credentials");
- registry.addMapping("/**")
- .allowedHeaders("*")
- .allowedMethods("*")
- .allowCredentials(true)
- .allowedOriginPatterns("*");
- }
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(sessionInterceptor);// 多次请求监听拦截
- registry.addInterceptor(new JWTIntercept())
- .addPathPatterns("/**") //拦截所有请求/**
- .excludePathPatterns("/personal/*").excludePathPatterns("/supplier/*"); //放心登录接口,因为要通过登录获取token
- }
- }
|